Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions docs/tools/quantization.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,18 @@ per-preset bucket policy for every canonical tensor name.
|----------|-----------------------------------------------------------------------|------------------------------------------------|
| `Linear` | `ggml_mul_mat` operands: encoder FF, attention projections, predictor LSTM gates, joint projections, head | Block-quantized (Q4_K / Q5_K / Q6_K / Q8_0) |
| `Embed` | Decoder token embedding (`dec.embed.token.weight`, `dec.token_embd.weight`) | Bumped to Q6_K in `_M` presets where shape-compatible, else `linear_fallback` |
| `ConvPw` | 1×1 pointwise conv kernels in conformer blocks | F16 (im2col+matmul supports F16 matmul) |
| `ConvPw` | 1×1 pointwise conv kernels still stored 3-D (`[1, in, out]`; legacy layouts only) | F16 (im2col+matmul supports F16 matmul) |
| `Conv` | Non-pointwise conv kernels: 2D pre-encode, depthwise | F32 or F16 (no quantized im2col in ggml) |
| `Norm` | Biases, LayerNorm/BatchNorm/RMSNorm weights, per-head q_norm/k_norm, positional bias/encoding, frontend buffers | F32 (precision-sensitive, tiny) |

Pointwise 1×1 convs converted to the 2-D `[in, out]` layout are ordinary
`Linear` operands and quantize; only legacy 3-D pointwise tensors stay
`ConvPw`/F16 because a 1-element row cannot be block-quantized.
Classification rules live in `classify_tensor()` in
`tools/transcribe-quantize/policy.cpp`. They are substring-based on the
canonical tensor name (e.g. `norm_*`, `*.bias`, `*pointwise*.weight`,
`*.q_norm.weight`, `*.ln_pre.weight`).
`*.q_norm.weight`, `*.ln_pre.weight`), plus the `ne0 == 1` layout test
that routes legacy pointwise tensors to `ConvPw`.

## Preset table

Expand Down
13 changes: 12 additions & 1 deletion scripts/convert-parakeet.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
Layout notes:
NeMo ships pure PyTorch tensors, so Conv2d/Conv1d weights are
already in the OIHW / [O, I_per_group, k] layouts the loader
expects — no transposes here.
expects — no transposes here. The one reshape is the conformer
1x1 pointwise pair: [out, in, 1] is squeezed to [out, in] so the
quantizer treats it as a linear layer (issue #281); memory order is
unchanged and the loader accepts the legacy 3-D layout too.

PyTorch's LSTM stores per-layer weights as
weight_ih_l{i} / weight_hh_l{i} and *two* bias vectors
Expand Down Expand Up @@ -2065,6 +2068,14 @@ def add(nemo_name: str, gguf_name: str) -> None:
if nemo_name not in sd_keys:
raise KeyError(f"state_dict missing tensor: {nemo_name!r}")
arr = tensor_to_fp32_numpy(sd[nemo_name])
# A 1x1 conv is a linear layer: [out, in, 1] and [out, in] have
# the same memory order. Store the conformer pointwise pair 2-D
# ([out, in]) so the quantizer classifies them as Linear instead
# of pinning 48 tensors per 0.6B model at F16 (issue #281). The
# loader accepts both the legacy 3-D and the new 2-D layout.
if ".conv.pointwise1.weight" in gguf_name or ".conv.pointwise2.weight" in gguf_name:
if arr.ndim == 3 and arr.shape[2] == 1:
arr = np.ascontiguousarray(arr.squeeze(axis=2))
writer.add_tensor(gguf_name, arr)
consumed.add(nemo_name)
bytes_out += int(arr.nbytes)
Expand Down
26 changes: 24 additions & 2 deletions src/arch/parakeet/weights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,28 @@ constexpr const char * kTag = kFamilyTag;
(slot) = _t; \
} while (0)

// Pointwise 1x1 convs: legacy GGUFs store [1, in, out] (Conv1d k=1),
// new converters store squeezed 2-D [in, out] so the quantizer treats
// them as Linear (issue #281). Accept both; the graph reshapes to 2-D
// either way and the memory order is identical. Peek at the layout
// first so find_tensor is called once and never logs a spurious
// shape-mismatch for the layout that is not present.
#define GET_PW(slot, name, in_dim, out_dim) \
do { \
const ggml_tensor * _raw = ggml_get_tensor(ctx_meta, (name)); \
ggml_tensor * _t = nullptr; \
if (_raw != nullptr && _raw->ne[0] == 1 && _raw->ne[2] == (out_dim)) { \
_t = transcribe::weights::find_tensor(ctx_meta, (name), { TRANSCRIBE_QUANT_CONV_TYPES }, \
{ 1, (in_dim), (out_dim) }, kTag); \
} else { \
_t = transcribe::weights::find_tensor(ctx_meta, (name), { TRANSCRIBE_QUANT_LINEAR_TYPES }, \
{ (in_dim), (out_dim) }, kTag); \
} \
if (_t == nullptr) \
return TRANSCRIBE_ERR_GGUF; \
(slot) = _t; \
} while (0)

} // namespace

transcribe_status build_parakeet_weights(ggml_context * ctx_meta,
Expand Down Expand Up @@ -949,9 +971,9 @@ transcribe_status build_parakeet_weights(ggml_context * ctx_meta,
// back to d_model.
GET_F32(b.norm_conv_w, lname("enc.blocks.%d.norm_conv.weight", i), d_model);
GET_F32(b.norm_conv_b, lname("enc.blocks.%d.norm_conv.bias", i), d_model);
GET_CONV(b.conv_pw1_w, lname("enc.blocks.%d.conv.pointwise1.weight", i), 1, d_model, 2 * d_model);
GET_PW(b.conv_pw1_w, lname("enc.blocks.%d.conv.pointwise1.weight", i), d_model, 2 * d_model);
GET_CONV(b.conv_dw_w, lname("enc.blocks.%d.conv.depthwise.weight", i), k, 1, d_model);
GET_CONV(b.conv_pw2_w, lname("enc.blocks.%d.conv.pointwise2.weight", i), 1, d_model, d_model);
GET_PW(b.conv_pw2_w, lname("enc.blocks.%d.conv.pointwise2.weight", i), d_model, d_model);
GET_F32(b.conv_bn_w, lname("enc.blocks.%d.conv.bn.weight", i), d_model);
GET_F32(b.conv_bn_b, lname("enc.blocks.%d.conv.bn.bias", i), d_model);
if (hp.enc_conv_norm_type == ParakeetHParams::ConvNormType::BatchNorm) {
Expand Down
4 changes: 2 additions & 2 deletions src/arch/parakeet/weights.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,11 @@ struct ParakeetBlock {
// Convolution module: pointwise -> GLU -> depthwise -> BN -> activation -> pointwise.
ggml_tensor * norm_conv_w = nullptr; // [d_model]
ggml_tensor * norm_conv_b = nullptr; // [d_model]
ggml_tensor * conv_pw1_w = nullptr; // [2*d_model, d_model, 1] conv1d k=1; 2x for GLU
ggml_tensor * conv_pw1_w = nullptr; // [d_model, 2*d_model] 2-D, or legacy [1, d_model, 2*d_model]; 2x for GLU
ggml_tensor * conv_pw1_b = nullptr; // [2*d_model], nullable (use_bias)
ggml_tensor * conv_dw_w = nullptr; // [d_model, 1, k] depthwise conv1d
ggml_tensor * conv_dw_b = nullptr; // [d_model], nullable (use_bias)
ggml_tensor * conv_pw2_w = nullptr; // [d_model, d_model, 1] conv1d k=1
ggml_tensor * conv_pw2_w = nullptr; // [d_model, d_model] 2-D, or legacy [1, d_model, d_model]
ggml_tensor * conv_pw2_b = nullptr; // [d_model], nullable (use_bias)
ggml_tensor * conv_bn_w = nullptr; // [d_model] BN scale
ggml_tensor * conv_bn_b = nullptr; // [d_model] BN shift
Expand Down
11 changes: 9 additions & 2 deletions src/conformer/conformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,18 @@ ggml_tensor * conv_module(ggml_context * ctx, ggml_tensor * x, const BlockView &
// conv_pad_mask no longer broadcasts and ggml aborts. Force the
// batch-aware direct path at B > 1 regardless of backend policy or
// TRANSCRIBE_CONV_NO_DIRECT_PW (correctness beats the perf override).
const bool direct_pw = policy.direct_pw || B > 1;
// 2-D pointwise weights (issue #281, squeezed [in, out]) have no
// kernel axis for the im2col path, so they also force direct.
// 3-D legacy is ne=[1, in, out]; 2-D is ne=[in, out, 1, ...]. The
// loader accepts each weight's layout independently, so either one
// being 2-D makes the im2col path invalid.
const bool pw1_is_2d = (b.conv_pw1_w == nullptr) || (b.conv_pw1_w->ne[2] == 1);
const bool pw2_is_2d = (b.conv_pw2_w == nullptr) || (b.conv_pw2_w->ne[2] == 1);
const bool direct_pw = policy.direct_pw || B > 1 || pw1_is_2d || pw2_is_2d;

if (direct_pw) {
// Pointwise conv 1 as direct mul_mat in [d_model, T, B] layout.
// Kernel ne=[1, d_model, 2*d_model] → reshape to [d_model, 2*d_model].
// 2-D [d_model, 2*d_model] or legacy [1, d_model, 2*d_model] → reshape.
// Force F32 accumulation for F16 weights (see mul_mat_f32acc in
// causal_lm.cpp for the CUDA COMPUTE_16F saturation rationale).
{
Expand Down
4 changes: 2 additions & 2 deletions src/conformer/conformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ struct BlockView {
// Convolution module. Pointwise conv1 is 2*d_model for GLU.
ggml_tensor * norm_conv_w = nullptr; // [d_model]
ggml_tensor * norm_conv_b = nullptr; // [d_model]
ggml_tensor * conv_pw1_w = nullptr; // [1, d_model, 2*d_model]
ggml_tensor * conv_pw1_w = nullptr; // [1, d_model, 2*d_model] or 2-D [d_model, 2*d_model]
ggml_tensor * conv_pw1_b = nullptr; // [2*d_model], nullable
ggml_tensor * conv_dw_w = nullptr; // [k, 1, d_model]
ggml_tensor * conv_dw_b = nullptr; // [d_model], nullable
ggml_tensor * conv_pw2_w = nullptr; // [1, d_model, d_model]
ggml_tensor * conv_pw2_w = nullptr; // [1, d_model, d_model] or 2-D [d_model, d_model]
ggml_tensor * conv_pw2_b = nullptr; // [d_model], nullable
// Post-depthwise normalisation. Exactly one pair is populated per block
// per BlockParams::conv_norm_type: BatchNorm (conv_bn_fused_*, fused at
Expand Down
5 changes: 4 additions & 1 deletion tests/fixtures/make_gguf_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,10 @@ def _parakeet_tensor_descriptors(causal_pre_encode: bool = False) -> list[tuple[

(f"enc.blocks.{i}.norm_conv.weight", [d_model]),
(f"enc.blocks.{i}.norm_conv.bias", [d_model]),
(f"enc.blocks.{i}.conv.pointwise1.weight", [1, d_model, 2 * d_model]),
# pointwise1 is stored 2-D (the converter's new layout, #281);
# pointwise2 stays legacy 3-D so the loader's fallback branch is
# covered too. Both have identical memory order.
(f"enc.blocks.{i}.conv.pointwise1.weight", [d_model, 2 * d_model]),
(f"enc.blocks.{i}.conv.depthwise.weight", [k, 1, d_model]),
(f"enc.blocks.{i}.conv.pointwise2.weight", [1, d_model, d_model]),
(f"enc.blocks.{i}.conv.bn.weight", [d_model]),
Expand Down