Class MarlinWeightPacker
java.lang.Object
smile.llm.quant.MarlinWeightPacker
Packs HuggingFace GPTQ / AWQ INT4 tensors into Marlin layout for
MarlinLinear. Invoked only when WeightGemmBackend.MARLIN
is selected (Ampere/Ada).
Default HF load path uses packAwqDirect(Tensor, Tensor, Tensor, int, Device, Integer) / packGptqDirect(Tensor, Tensor, Tensor, Tensor, int, Device, Integer)
(dequant → optional RoPE permute → Marlin requant). packFromFp16(Tensor, int, Device)
remains for tests and dense requant.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordResult of packing: Marlin qweight, scales, logical features. -
Method Summary
Modifier and TypeMethodDescriptionstatic MarlinWeightPacker.PackedPacks AutoAWQ GEMM tensors into Marlin layout.static MarlinWeightPacker.PackedpackAwqDirect(Tensor qweight, Tensor scales, Tensor qzeros, int groupSize, Device device) AWQ→Marlin pack without RoPE rearrange.static MarlinWeightPacker.PackedpackAwqDirect(Tensor qweight, Tensor scales, Tensor qzeros, int groupSize, Device device, Integer ropeHeads) AWQ→Marlin pack with optional HF→Meta RoPE rearrange on out-features.static MarlinWeightPacker.PackedpackFromFp16(Tensor weightFp16, int groupSize, Device device) Packs a dense FP16 weight[out, in]into Marlin INT4 layout matching upstreammarlin.Layer.pack(Bis[k/16, n*16/8]).static MarlinWeightPacker.PackedPacks GPTQ tensors into Marlin layout (FP16 dequant→requant; act-order rejected).static MarlinWeightPacker.PackedpackGptqDirect(Tensor qweight, Tensor scales, Tensor qzeros, Tensor gIdx, int groupSize, Device device) Direct GPTQ→Marlin pack without RoPE rearrange.static MarlinWeightPacker.PackedpackGptqDirect(Tensor qweight, Tensor scales, Tensor qzeros, Tensor gIdx, int groupSize, Device device, Integer ropeHeads) Direct GPTQ→Marlin pack.static TensorreversePermuteHfToMeta(Tensor w, int nHeads) HuggingFace interleaved Q/K layout → Meta / GPT-NeoX layout used by Smile RoPE.
-
Method Details
-
packGptq
public static MarlinWeightPacker.Packed packGptq(Tensor qweight, Tensor scales, Tensor qzeros, Tensor gIdx, int groupSize, Device device) Packs GPTQ tensors into Marlin layout (FP16 dequant→requant; act-order rejected).- Parameters:
qweight- GPTQ packed weights.scales- group scales.qzeros- packed zeros, ornull.gIdx- GPTQg_idx, ornull.groupSize- quantization group size.device- destination device.- Returns:
- Marlin-packed tensors.
-
packAwq
public static MarlinWeightPacker.Packed packAwq(Tensor qweight, Tensor scales, Tensor qzeros, int groupSize, Device device) Packs AutoAWQ GEMM tensors into Marlin layout.Dequantizes with AWQ zeros (exact), then requants into Marlin's symmetric int4 (zp=8). Folding zeros into int4 with clamp is unsafe when
|q - z| > 7.- Parameters:
qweight- AWQ packed weights.scales- group scales.qzeros- packed zeros, ornull.groupSize- quantization group size.device- destination device.- Returns:
- Marlin-packed tensors.
-
packAwqDirect
public static MarlinWeightPacker.Packed packAwqDirect(Tensor qweight, Tensor scales, Tensor qzeros, int groupSize, Device device, Integer ropeHeads) AWQ→Marlin pack with optional HF→Meta RoPE rearrange on out-features.- Parameters:
qweight- AWQ packed weights.scales- group scales.qzeros- packed zeros, ornull.groupSize- quantization group size.device- destination device.ropeHeads- if non-null, permute[out,in]for Meta-style RoPE (num_attention_headsornum_kv_heads).- Returns:
- Marlin-packed tensors.
-
packAwqDirect
public static MarlinWeightPacker.Packed packAwqDirect(Tensor qweight, Tensor scales, Tensor qzeros, int groupSize, Device device) AWQ→Marlin pack without RoPE rearrange.- Parameters:
qweight- AWQ packed weights.scales- group scales.qzeros- packed zeros, ornull.groupSize- quantization group size.device- destination device.- Returns:
- Marlin-packed tensors.
- See Also:
-
reversePermuteHfToMeta
HuggingFace interleaved Q/K layout → Meta / GPT-NeoX layout used by Smile RoPE. Same transform as denseLlama.reversePermuteon[out, in]weights.- Parameters:
w- weight[out, in].nHeads- attention or KV head count.- Returns:
- permuted weight (caller owns).
-
packGptqDirect
public static MarlinWeightPacker.Packed packGptqDirect(Tensor qweight, Tensor scales, Tensor qzeros, Tensor gIdx, int groupSize, Device device, Integer ropeHeads) Direct GPTQ→Marlin pack. Act-order (g_idxnot sequential) fails fast.Dequantizes (with zeros when present), optionally applies HF→Meta RoPE rearrange, then requants into Marlin symmetric int4.
- Parameters:
qweight- GPTQ packed weights.scales- group scales.qzeros- packed zeros, ornull.gIdx- GPTQg_idx, ornull.groupSize- quantization group size.device- destination device.ropeHeads- if non-null, permute out-features for Meta-style RoPE.- Returns:
- Marlin-packed tensors.
-
packGptqDirect
public static MarlinWeightPacker.Packed packGptqDirect(Tensor qweight, Tensor scales, Tensor qzeros, Tensor gIdx, int groupSize, Device device) Direct GPTQ→Marlin pack without RoPE rearrange.- Parameters:
qweight- GPTQ packed weights.scales- group scales.qzeros- packed zeros, ornull.gIdx- GPTQg_idx, ornull.groupSize- quantization group size.device- destination device.- Returns:
- Marlin-packed tensors.
- See Also:
-
packFromFp16
public static MarlinWeightPacker.Packed packFromFp16(Tensor weightFp16, int groupSize, Device device) Packs a dense FP16 weight[out, in]into Marlin INT4 layout matching upstreammarlin.Layer.pack(Bis[k/16, n*16/8]).- Parameters:
weightFp16- dense FP16 weight[out, in].groupSize- quantization group size.device- destination device.- Returns:
- Marlin-packed tensors.
-