import io import json from pathlib import Path from types import SimpleNamespace import struct import tempfile import time import unittest from unittest.mock import patch from fastapi.testclient import TestClient import ml_dtypes import numpy as np from tensor_pruning import prune_queries from tensor_pruning.checkpoint import _queries, prune_checkpoint from tensor_pruning.service import create_app def _name(layer): return f"model.layers.{layer}.self_attn.q_proj.weight" def _shard(path, entries, *, sparse=False): header, offset = {}, 0 for name, dtype, shape, length, _ in entries: header[name] = dict(dtype=dtype, shape=shape, data_offsets=[offset, offset + length]) offset += length raw = json.dumps(header).encode() raw += b" " * (-len(raw) % 8) with path.open("wb") as f: f.write(struct.pack("