agentleFS
guoqingbaoguoqingbao/vllm.rs/.cursor/skills/check-model/SKILL.md

check-model

Skill345 starsChanged 6 months agoMITView on GitHub

Check model compatibility with xinfer before loading. Validates config.json, weight tensor shapes and naming, quantization format correctness, and multi-rank (tensor-parallel) divisibility. Use when the user asks to check, validate, audit, or verify a model will load correctly — from a HuggingFace URL/config, local path, or pasted tensor info.

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. edu6565/claude-skills★ 0same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository2 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    If tensor info is missing, ask the user to provide it.

    line 25
  2. Distinctive:

    Check: No extra scale/packed tensors should be present.

    line 128
  3. Very specific:

    Check: Not applicable for safetensors checks.

    line 171
  4. Very specific:

    If a linear_attn sublayer is in the ignore list and has only BF16 weight, the detection returns false, and the layer loads as unquantized.

    line 197

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Check Model — Pre-Load Compatibility Audit for xinfer

Phase 0: Gather Model Information

Collect model config and tensor info. Accept any of:

InputHow to use
HuggingFace config URLFetch config.json from the URL (e.g. https://huggingface.co/<id>/blob/main/config.json)
HuggingFace model IDFetch config from https://huggingface.co/<id>/raw/main/config.json
Local model pathRead <path>/config.json directly
Pasted config JSONParse inline
Tensor infoUser pastes tensor names/shapes/dtypes from HuggingFace safetensor viewer or provides local weights

If tensor info is missing, ask the user to provide it. They can get it by clicking any .safetensors file in the HuggingFace model page and copying the tensor tree.

For local models, extract tensor info with:

import json, struct, sys, glob, os
path = sys.argv[1]
for sf in sorted(glob.glob(os.path.join(path, "*.safetensors"))):
    with open(sf, "rb") as f:
        n = struct.unpack("<Q", f.read(8))[0]
        header = json.loads(f.read(n))
    for k, v in sorted(header.items()):
        if k != "__metadata__":
            print(f"{k}\t{v.get('shape')}\t{v.get('dtype')}")

Phase 1: Parse Config and Identify Model Type

Extract from config.json:

Core parameters

FieldRequiredNotes
architecturesYesDetermines model type and loader path
hidden_sizeYesOr nested under text_config for multimodal
num_attention_headsYesQ heads for full attention
num_key_value_headsYesKV heads for GQA
head_dimIf availableDefaults to hidden_size / num_attention_heads
num_hidden_layersYesTotal layer count
vocab_sizeYesEmbedding table size

Hybrid (Qwen3.5/Qwen3Next) parameters

FieldWhen presentNotes
layer_typesQwen3.5/Qwen3NextArray of "linear_attention" / "full_attention"
linear_num_key_headsHybrid modelsGDN K heads (may differ from V heads)
linear_num_value_headsHybrid modelsGDN V heads
linear_key_head_dimHybrid modelsPer-head K dimension
linear_value_head_dimHybrid modelsPer-head V dimension
linear_conv_kernel_dimHybrid modelsConv1d kernel size (typically 4)
full_attention_intervalHybrid modelsHow often full attention appears

MoE parameters

FieldWhen presentNotes
num_expertsMoE modelsExpert count per layer
num_experts_per_tokMoE modelsTop-K routing
moe_intermediate_sizeMoE modelsPer-expert FFN hidden dim
shared_expert_intermediate_sizeSome MoEShared expert dim

Quantization config

FieldNotes
quantization_config.quant_method"modelopt", "compressed-tensors", "fp8", "gptq", "awq"
quantization_config.quant_algoFor modelopt: "NVFP4", "FP4"
quantization_config.formatFor compressed-tensors: "nvfp4-pack-quantized", "mxfp4-pack-quantized"
quantization_config.config_groupsWeight/activation quant specs
quantization_config.ignoreLayers excluded from quantization (stored as BF16/FP16)
quantization_config.weight_block_sizeFP8 block dimensions (e.g. [128, 128])

Normalize quant_method

Apply the same normalization as QuantConfig::normalize_compressed_tensors():

Raw quant_methodquant_algo / formatNormalized
modeloptNVFP4 or FP4nvfp4
modelopt(detect from config_groups)nvfp4
compressed-tensorsformat contains nvfp4nvfp4
compressed-tensorsformat contains mxfp4mxfp4
fp8-fp8
gptq-gptq
awq-awq

Phase 2: Validate Tensor Format Against Quantization Config

For each layer type, check that tensor names and dtypes match the expected format.

2a. Determine which layers are quantized vs skipped

Parse the ignore list from quantization_config. Layers in the ignore list should have BF16/FP16 weights (weight tensor only). Layers NOT in the ignore list should have quantized tensors.

The ignore list supports:

  • Literal paths: "model.language_model.layers.0.linear_attn.in_proj_qkv"
  • Regex patterns: "re:.*linear_attn.*"
  • Glob-style wildcards: "model.visual*", "mtp.layers.0*"

2b. Format-specific tensor checks

Unquantized (BF16/FP16)

Expected tensors per linear layer:

  • weight — dtype BF16 or F16, shape [out_dim, in_dim]
  • bias (optional) — dtype BF16 or F16

Check: No extra scale/packed tensors should be present.

FP8 (quant_method == "fp8")

Expected tensors per linear layer:

  • weight — dtype U8 (F8_E4M3), shape [out_dim, in_dim]
  • weight_scale or weight_scale_inv — dtype F32, shape [out_dim/by, in_dim/bx] where [by, bx] = weight_block_size (default [128, 128])
  • bias (optional)

Check: weight_block_size must have exactly 2 elements. Scale dimensions must match ceil(out_dim/by) x ceil(in_dim/bx).

NVFP4 — ModelOpt format (quant_method == "modelopt" + quant_algo == "NVFP4")

Expected tensors per quantized linear layer:

  • weight — dtype U8, shape [out_dim, in_dim/2] (packed FP4, 2 values per byte)
  • weight_scale — dtype F8_E4M3 (U8), shape [out_dim, in_dim/16] (group_size=16)
  • weight_scale_2 — dtype F32, scalar (global weight scale, direct multiplier)
  • input_scale — dtype F32, scalar (activation scale)

Check: weight shape dim1 must be exactly in_dim/2. Scale dim1 must be in_dim/16.

NVFP4 — Compressed-tensors format (quant_method == "compressed-tensors" + nvfp4 format)

Expected tensors per quantized linear layer:

  • weight_packed — dtype U8, shape [out_dim, in_dim/2]
  • weight_scale — dtype F8_E4M3 (U8), shape [out_dim, in_dim/16]
  • weight_global_scale — dtype F32, scalar or [1] (divisor, inverted at load time)
  • input_global_scale — dtype F32, scalar or [1] (divisor, inverted at load time)

Check: Same shape rules as ModelOpt, but different tensor names.

MXFP4 (quant_method == "mxfp4" or compressed-tensors with mxfp4)

Expected tensors per quantized linear layer:

  • weight_packed or blocks — dtype U8, shape [out_dim, in_dim/2]
  • weight_scale or scales — dtype U8 (F8_E8M0), shape [out_dim, in_dim/32] (group_size=32)

Check: Scale dim1 must be in_dim/32.

GGUF

GGUF models are self-contained (no config.json). Weight tensor names use blk.{i} prefix mapped to model.layers.{i}. Quantization is per-tensor via GGML dtypes (Q4_K, Q6_K, Q8_0, etc.).

Check: Not applicable for safetensors checks. GGUF has its own loader path via QLinear / QMatMul.

2c. Loader path tensor name resolution

The xinfer loaders try tensor names in priority order. Verify the model's tensors match at least one:

ComponentTensor name priority (first match wins)
NVFP4/MXFP4 packed weightsweight_packed > weight > blocks
NVFP4/MXFP4 scalesweight_scale > scales
NVFP4 global scaleweight_global_scale (inverted) > weight_scale_2 (direct)
NVFP4 input scaleinput_scale (direct) > input_global_scale (inverted)
FP8 scaleweight_scale > weight_scale_inv

Flag any mismatch where the model uses a tensor name not in the priority list.

2d. Hybrid model (GDN) quantization detection

For Qwen3.5/Qwen3Next models with quantization config, the GatedDeltaNet layer has its own quantization detection (is_weight_quantized) that checks each linear_attn sublayer independently:

quant_methodDetection logic
fp8Has weight_scale or weight_scale_inv
mxfp4Has weight_packed or blocks
nvfp4(weight_packed or blocks) AND (weight_scale or scales) OR (weight_scale_2 or input_scale) AND (weight_scale or scales)

If a linear_attn sublayer is in the ignore list and has only BF16 weight, the detection returns false, and the layer loads as unquantized. Verify this matches the tensor info.


Phase 3: Multi-Rank Divisibility Analysis

For each candidate world_size in [1, 2, 4, 8], check all TP-sharded dimensions.

3a. Full Attention

ComponentGlobal dimShard dimDivisibility requirement
Q projectionnum_attention_heads * head_dimdim 0num_attention_heads % world_size == 0
K/V projectionnum_kv_heads * head_dimdim 0num_kv_heads >= world_size: num_kv_heads % world_size == 0; num_kv_heads < world_size: world_size % num_kv_heads == 0 (replicated KV mode)
O projectionnum_attention_heads * head_dimdim 1Same as Q

For quantized (FP8/NVFP4/MXFP4) Q/K/V:

  • Column linear shard dim 0: per-rank out_dim / world_size must be cleanly divisible
  • For FP8: per-rank start must be aligned to weight_block_size[0] (default 128)
  • For NVFP4: per-rank output must be divisible (no block alignment needed for dim 0 shard)

3b. GatedDeltaNet (Linear Attention)

ComponentGlobal dimRequirement
num_v_headslinear_num_value_heads% world_size == 0
num_k_headslinear_num_key_heads% world_size == 0
in_proj_qkv (merged)Q=key_dim_global, K=key_dim_global, V=value_dim_globalEach chunk % world_size == 0
in_proj_zvalue_dim_global% world_size == 0
in_proj_b/anum_v_heads_global% world_size == 0
A_log / dt_biasnum_v_heads_global% world_size == 0
conv1d (Q block)key_dim_globalkey_dim / world_size channels per rank
conv1d (V block)value_dim_global% world_size == 0
out_projvalue_dim_globalRow linear dim 1 % world_size == 0

Where:

  • key_dim_global = linear_num_key_heads * linear_key_head_dim
  • value_dim_global = linear_num_value_heads * linear_value_head_dim

3c. MoE Experts

ComponentGlobal dimShard dimRequirement
gate/up_projmoe_intermediate_sizedim 0% world_size == 0
down_projmoe_intermediate_sizedim 1% world_size == 0

For NVFP4/MXFP4 MoE:

  • gate/up packed dim0: moe_intermediate_size / world_size per rank
  • down packed dim1: (moe_intermediate_size / pack_factor) / world_size per rank

3d. Shared Expert MLP

Same rules as standard MLP with shared_expert_intermediate_size:

  • Column linear (gate/up): shared_expert_intermediate_size % world_size == 0
  • Row linear (down): shared_expert_intermediate_size % world_size == 0

3e. NVFP4/MXFP4 Scale Alignment

For NVFP4 (group_size=16): after sharding, verify per_rank_in_dim % 16 == 0 for dim-1 shards. For MXFP4 (group_size=32): verify per_rank_in_dim % 32 == 0 for dim-1 shards. For FP8: verify per-rank boundaries align to weight_block_size.

3f. Embedding / LM Head

  • embed_tokens: replicated (not sharded), no divisibility constraint.
  • lm_head: replicated, no constraint. But if tie_word_embeddings is true, verify lm_head doesn't exist as a separate tensor (should reuse embed_tokens.weight).

Phase 4: Report Findings

Present results in a structured format:

Model Summary

Architecture: Qwen3_5MoeForConditionalGeneration
Model Type: qwen3_5_moe (Hybrid MoE with linear attention)
Quantization: nvfp4 (compressed-tensors format)
Layers: 48 (36 linear_attention + 12 full_attention)
Hidden size: 3072
Full attention: 32 Q heads, 2 KV heads, head_dim=256
Linear attention: 16 K heads, 64 V heads, head_dim=128
MoE: 256 experts, top-8, intermediate=1024
Shared expert: intermediate=1024

Tensor Format Validation

[OK] Linear attention layers (BF16, in ignore list)
[OK] Full attention layers (NVFP4 compressed-tensors: weight_packed + weight_scale + weight_global_scale)
[OK] MoE experts (NVFP4 compressed-tensors: per-expert weight_packed)
[OK] Shared expert MLP (NVFP4 compressed-tensors: weight_packed)
[WARN] lm_head: in ignore list, stored as BF16

Multi-Rank Compatibility

| Component | 1 GPU | 2 GPUs | 4 GPUs | 8 GPUs |
|-----------|-------|--------|--------|--------|
| Full attn Q heads (32) | OK | 16 | 8 | 4 |
| Full attn KV heads (2) | OK | 1 | repl(2) | repl(4) |
| GDN K heads (16) | OK | 8 | 4 | 2 |
| GDN V heads (64) | OK | 32 | 16 | 8 |
| MoE inter (1024) | OK | 512 | 256 | 128 |
| Overall | OK | OK | OK | OK |

Issues Found

Flag any problems:

  • [ERROR] — Will fail to load (missing tensors, wrong names, indivisible dims)
  • [WARN] — May cause issues (unusual format, edge case)
  • [INFO] — Informational (features detected, fallback paths)

Phase 5: Common Issues Reference

Known tensor name mismatches

Model sourcePacked weight namexinfer loader support
ModelOpt NVFP4weight (U8)Single-GPU: OK. Multi-GPU merged chunks: requires weight fallback in load_merged_chunks
Compressed-tensors NVFP4weight_packedOK everywhere
Legacy MXFP4/NVFP4blocksOK (final fallback)

GatedDeltaNet TP-safe loading

The in_proj_qkv tensor requires special merged-chunk loading for multi-GPU:

  • MergedParallelColumnLinear::load_merged_chunks splits Q, K, V independently
  • For quantized models (FP8/NVFP4/MXFP4), each chunk must be sharded within the quantized domain
  • For BF16 (ignore-listed layers), falls through to the unquantized path

Replicated KV heads

When num_kv_heads < world_size:

  • kv_head_shard uses replicated mode: ranks_per_kv_head = world_size / num_kv_heads
  • Each KV head is shared by ranks_per_kv_head consecutive ranks
  • Requires world_size % num_kv_heads == 0

Key Source Files

FileRelevance
src/models/layers/distributed.rsTP column/row linear, load_merged_chunks, kv_head_shard
src/models/layers/linear.rsLnFp8, LnNvfp4, LnMxfp4 loaders, tensor name resolution
src/models/layers/deltanet.rsGatedDeltaNet loading, is_weight_quantized, projection sharding
src/models/layers/attention.rsFull attention QKV loading, packed QKV for FP8
src/models/layers/moe.rsFusedMoeNvfp4, FusedMoeMxfp4, FusedMoeFp8 expert loading
src/utils/config.rsQuantConfig, normalize_compressed_tensors, should_skip_module

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.