probe(round two): W8A8 int8-dynamic scheme — kernel isolation, raw-op probe, artifact builder support
Build Wheel / build (3.11) (pull_request) Failing after 42s
Build Wheel / build (3.12) (pull_request) Failing after 42s
pre-commit / pre-commit (pull_request) Failing after 53s

This commit is contained in:
admin committed 2026-10-08 08:58:45 -04:00
1 parent bf65a41ceb
commit 704b8e29ae
3 files changed
+304 -19

No files matched your search

+63 -19
View File
@@ -61,8 +61,14 @@ SYMLINKED_COMPONENTS = ("scheduler", "text_encoder", "vae", "processor")
SYMLINKED_FILES = ("model_index.json",)
def build_quantization_dict() -> dict:
"""Serialized compressed-tensors int8 weight-only metadata (llm-compressor schema)."""
def build_quantization_dict(scheme: str) -> dict:
"""Serialized compressed-tensors metadata (llm-compressor schema).
scheme="int8wo": int8 weight-only, pack-quantized storage.
scheme="w8a8dyn": int8 weights (static per-channel) + dynamic per-token
symmetric int8 activations, int-quantized storage — the non-Marlin
cutlass path on sm_86.
"""
weights = QuantizationArgs(
num_bits=8,
type=QuantizationType.INT,
@@ -71,10 +77,21 @@ def build_quantization_dict() -> dict:
dynamic=False,
observer="minmax",
)
scheme = QuantizationScheme(targets=["Linear"], weights=weights)
input_activations = (
QuantizationArgs(
num_bits=8,
type=QuantizationType.INT,
symmetric=True,
strategy=QuantizationStrategy.TOKEN,
dynamic=True,
)
if scheme == "w8a8dyn"
else None
)
scheme_obj = QuantizationScheme(targets=["Linear"], weights=weights, input_activations=input_activations)
config = QuantizationConfig(
config_groups={"group_0": scheme},
format=CompressionFormat.pack_quantized,
config_groups={"group_0": scheme_obj},
format=CompressionFormat.int_quantized if scheme == "w8a8dyn" else CompressionFormat.pack_quantized,
ignore=list(IGNORED_TARGETS),
quant_method="compressed-tensors",
quantization_status=QuantizationStatus.FROZEN,
@@ -90,26 +107,39 @@ def sha256_file(path: Path) -> str:
return digest.hexdigest()
def quantize_weight(weight: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor, dict]:
"""Per-output-channel symmetric int8: q = round(W/s), s = rowmax(|W|)/127.
def quantize_weight(weight: torch.Tensor, scheme: str) -> tuple[dict[str, torch.Tensor], dict]:
"""Per-output-channel symmetric int8.
Returns (weight_packed int32 [out, in/4], weight_scale fp32 [out, 1],
stats) using compressed-tensors' packer (uint8 biased by 128, 4 per int32).
scheme="int8wo": q = round(W/s), s = rowmax(|W|)/127, packed via
compressed-tensors' packer (uint8 biased by 128, 4 per int32).
scheme="w8a8dyn": same quantization, stored unpacked as plain int8
(int-quantized format) with fp32 scales.
"""
w = weight.detach().to(torch.float32)
scale = w.abs().amax(dim=1, keepdim=True).clamp_min(1e-12) / 127.0
q = torch.round(w / scale).clamp(-127, 127).to(torch.int8)
packed = pack_to_int32(q.contiguous(), 8).contiguous()
dequant = q.to(torch.float32) * scale
err = (w - dequant).norm() / w.norm().clamp_min(1e-12)
stats = {"rel_l2": float(err), "out": int(w.shape[0]), "in": int(w.shape[1])}
return packed, scale.to(torch.float32).contiguous(), stats
if scheme == "w8a8dyn":
return {"weight": q.contiguous(), "weight_scale": scale.to(torch.float32).contiguous()}, stats
return {
"weight_packed": pack_to_int32(q.contiguous(), 8).contiguous(),
"weight_scale": scale.to(torch.float32).contiguous(),
"weight_shape": torch.tensor(weight.shape, dtype=torch.int64),
}, stats
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--snapshot", type=Path, required=True, help="sealed snapshot dir")
parser.add_argument("--out", type=Path, required=True, help="artifact dir to create")
parser.add_argument(
"--scheme",
choices=("int8wo", "w8a8dyn"),
default="int8wo",
help="int8 weight-only (pack-quantized, Marlin path) or W8A8 int8-dynamic (int-quantized, cutlass path)",
)
args = parser.parse_args()
snapshot = args.snapshot.resolve()
@@ -131,10 +161,16 @@ def main() -> int:
tensors = load_file(str(snapshot / "transformer" / shard))
for name, tensor in tensors.items():
if QUANTIZED_KEY.match(name):
packed, scale, stats = quantize_weight(tensor)
state[f"{name}_packed"] = packed
state[f"{name}_scale"] = scale
state[f"{name}_shape"] = torch.tensor(tensor.shape, dtype=torch.int64)
emitted, stats = quantize_weight(tensor, args.scheme)
if args.scheme == "w8a8dyn":
# int-quantized storage: plain int8 weight + scale, mirroring
# the vLLM layer parameter names (weight / weight_scale).
state[name] = emitted["weight"]
state[f"{name}_scale"] = emitted["weight_scale"]
else:
state[f"{name}_packed"] = emitted["weight_packed"]
state[f"{name}_scale"] = emitted["weight_scale"]
state[f"{name}_shape"] = emitted["weight_shape"]
quant_stats[name] = stats
quant_params += tensor.numel()
print(f"q {name} {tuple(tensor.shape)} rel_l2={stats['rel_l2']:.5f}", flush=True)
@@ -148,7 +184,7 @@ def main() -> int:
total_bytes = weights_path.stat().st_size
config = json.loads((snapshot / "transformer" / "config.json").read_text())
config["quantization_config"] = {"transformer": build_quantization_dict()}
config["quantization_config"] = {"transformer": build_quantization_dict(args.scheme)}
(artifact / "transformer" / "config.json").write_text(json.dumps(config, indent=2) + "\n")
for name in SYMLINKED_FILES:
@@ -166,9 +202,17 @@ def main() -> int:
entry["sha256"] = sha256_file(artifact / entry["path"])
tree_json = snapshot.parent.parent / "trees" / f"{SNAPSHOT_COMMIT}.json"
manifest = {
"schema": "issue5-int8wo-v1",
"schema": f"issue5-{args.scheme}-v1",
"created_utc": dt.datetime.now(dt.UTC).replace(microsecond=0).isoformat(),
"description": "Qwen-Image-2.1 DiT int8 weight-only (W8A16), compressed-tensors pack-quantized",
"description": (
f"Qwen-Image-2.1 DiT {args.scheme} "
+ (
"W8A8 int8-dynamic, int-quantized"
if args.scheme == "w8a8dyn"
else "int8 weight-only W8A16, pack-quantized"
)
+ ", compressed-tensors"
),
"inputs": {
"snapshot": str(snapshot),
"revision": SNAPSHOT_COMMIT,
@@ -184,7 +228,7 @@ def main() -> int:
"method": "compressed-tensors",
"format": "pack-quantized",
"weights": "int8 symmetric per-output-channel, static, minmax",
"config": build_quantization_dict(),
"config": build_quantization_dict(args.scheme),
"ignored_layers": list(IGNORED_TARGETS),
"note": "ignore list mirrors the vllm-omni model's quant_config=None boundary layers",
},