"""Read back which kernel and which activation path vLLM really built, layer by layer (vLLM 0.32.0). Used for content/standalone/05-quantization/15-humming-quantized-kernels (2026-10-29), arms C4 and C5: on an NVFP4 checkpoint, `--moe-backend humming` alone runs the experts with BF16 activations (the NVFP4 oracle passes no input schema), and only VLLM_HUMMING_INPUT_QUANT_CONFIG makes them W4A4. The startup log names the backend, not the activation path; this probe reads both from the loaded modules. VLLM_HUMMING_INPUT_QUANT_CONFIG='...' python humming_probe.py --model DIR --moe-backend humming --out probe-C5.json Offline LLM(...) with the arm's flags (the env var is inherited), then LLM.apply_model, which pickles the function to the engine-core worker: that needs VLLM_ALLOW_INSECURE_SERIALIZATION=1 (set here before vLLM is imported). Reads, from v0.32.0's module layout: - MoE: every RoutedExperts module (has .moe_config and .quant_method): the quant method class, the expert kernel (quant_method.moe_kernel.fused_experts), and, when Humming converted the layer, .input_schemas / .weight_schemas (dicts keyed "w13", "w2", set by convert_to_humming_moe_kernel_format) and the LayerConfig in .humming_configs. - Linear: layer 0's qkv_proj, o_proj: quant method, compressed-tensors scheme (.scheme), its kernel (.scheme.kernel, or .quant_method.kernel), and .weight_schema / .input_schema when a Humming linear kernel converted it. Layer 0 is printed in full; every layer is summarised (distinct values with their counts), so a mixed model shows up. A short greedy generation checks the model answers at all. Writes --out (JSON) and prints it. """ import argparse import json import os os.environ.setdefault("VLLM_ALLOW_INSECURE_SERIALIZATION", "1") def inspect_model(model): """Runs inside the worker. Returns plain strings only (no tensors).""" import collections import json import re def name_of(obj): return None if obj is None else type(obj).__name__ def short(obj, n=600): if obj is None: return None s = repr(obj) return s if len(s) <= n else s[:n] + "..." def schemas(d): if not isinstance(d, dict): return None return {k: short(v) for k, v in d.items()} def a_dtypes(d): # the activation dtype per sublayer: None means BF16/FP16 (no input quantization) if not isinstance(d, dict): return None return {k: (lambda x: "none (16-bit)" if x is None else str(x))(getattr(v, "a_dtype", "?")) for k, v in d.items()} def layer_index(name): m = re.search(r"layers\.(\d+)\.", name) return int(m.group(1)) if m else -1 moe, lin = [], [] for name, mod in model.named_modules(): if hasattr(mod, "moe_config") and hasattr(mod, "quant_method"): qm = mod.quant_method mk = getattr(qm, "moe_kernel", None) moe.append({ "name": name, "layer": layer_index(name), "module": name_of(mod), "quant_method": name_of(qm), "experts": name_of(getattr(mk, "fused_experts", None)) if mk is not None else None, "prepare_finalize": name_of(getattr(mk, "prepare_finalize", None)) if mk is not None else None, "humming": hasattr(mod, "humming_configs"), "input_a_dtype": a_dtypes(getattr(mod, "input_schemas", None)), "input_schemas": schemas(getattr(mod, "input_schemas", None)), "weight_schemas": schemas(getattr(mod, "weight_schemas", None)), "humming_configs": schemas(getattr(mod, "humming_configs", None)), }) elif re.search(r"\.(qkv_proj|o_proj)$", name) and hasattr(mod, "quant_method"): qm, scheme = mod.quant_method, getattr(mod, "scheme", None) kernel = getattr(scheme, "kernel", None) or getattr(qm, "kernel", None) lin.append({ "name": name, "layer": layer_index(name), "quant_method": name_of(qm), "scheme": name_of(scheme), "kernel": name_of(kernel), "weight_schema": short(getattr(mod, "weight_schema", None)), "input_schema": short(getattr(mod, "input_schema", None)), }) def summary(rows, keys): out = {} for k in keys: c = collections.Counter(json.dumps(r[k], sort_keys=True) for r in rows) out[k] = {v: n for v, n in c.most_common()} return out first_moe = min((r for r in moe), key=lambda r: r["layer"], default=None) first_lin = [r for r in lin if r["layer"] == min((x["layer"] for x in lin), default=-1)] return { "moe_layers": len(moe), "moe_layer0": first_moe, "moe_all_layers": summary(moe, ["quant_method", "experts", "input_a_dtype"]), "linear_layer0": first_lin, "linear_all_layers": summary(lin, ["quant_method", "scheme", "kernel"]), } def main(): ap = argparse.ArgumentParser() ap.add_argument("--model", required=True) ap.add_argument("--revision") ap.add_argument("--tokenizer") ap.add_argument("--moe-backend", default="auto") ap.add_argument("--linear-backend", default="auto") ap.add_argument("--gpu-memory-utilization", type=float, default=0.40) ap.add_argument("--max-model-len", type=int, default=4096) ap.add_argument("--out", required=True) a = ap.parse_args() from vllm import LLM, SamplingParams import vllm # enforce_eager: no CUDA graphs to capture, a faster start; backend and activation-path selection happen at # weight processing, before any graph capture, so they are the same as in the served arm. llm = LLM(model=a.model, revision=a.revision, tokenizer=a.tokenizer, moe_backend=a.moe_backend, linear_backend=a.linear_backend, gpu_memory_utilization=a.gpu_memory_utilization, max_model_len=a.max_model_len, max_num_seqs=8, enforce_eager=True) info = llm.apply_model(inspect_model)[0] gen = llm.generate(["The capital of France is"], SamplingParams(temperature=0, max_tokens=8))[0].outputs[0].text try: from importlib.metadata import version hv = version("humming-kernels") except Exception as e: # noqa: BLE001 hv = f"? ({e})" info.update({ "model": a.model, "revision": a.revision, "moe_backend": a.moe_backend, "linear_backend": a.linear_backend, "env_VLLM_HUMMING_INPUT_QUANT_CONFIG": os.environ.get("VLLM_HUMMING_INPUT_QUANT_CONFIG"), "vllm": vllm.__version__, "humming_kernels": hv, "generation": gen, }) json.dump(info, open(a.out, "w"), indent=1) print(json.dumps(info, indent=1)) if __name__ == "__main__": main()