Skip to content
Open
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
15 changes: 13 additions & 2 deletions scripts/convert-parakeet.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
already in the OIHW / [O, I_per_group, k] layouts the loader
expects — no transposes here.

The conformer pointwise Conv1d kernels ([O, I, 1]) are written 2-D
([O, I]) so transcribe-quantize treats them as Linear.

PyTorch's LSTM stores per-layer weights as
weight_ih_l{i} / weight_hh_l{i} and *two* bias vectors
(bias_ih_l{i}, bias_hh_l{i}) that are both added to the gate
Expand Down Expand Up @@ -1402,10 +1405,13 @@ def _from_module_or_cfg(attr: str, cfg_key: str, default=None):
# ---------------------------------------------------------------------------
#
# NeMo ships tensors in the layout the loader expects, so every entry
# is a plain passthrough. The ordering here is for human readability
# is a plain passthrough except POINTWISE_2D (written without the
# kernel axis). The ordering here is for human readability
# and matches src/arch/parakeet/weights.cpp; gguf-py writes tensors in
# add_tensor() call order, but the loader looks up by name.

POINTWISE_2D = ("conv.pointwise1.weight", "conv.pointwise2.weight")


ENCODER_BLOCK_TABLE: list[tuple[str, str]] = [
# Macaron FF1.
Expand Down Expand Up @@ -2060,11 +2066,15 @@ def convert(model_spec: str, out_path: Path, repo_id: str | None = None,
n_added = 0
bytes_out = 0

def add(nemo_name: str, gguf_name: str) -> None:
def add(nemo_name: str, gguf_name: str, drop_k: bool = False) -> None:
nonlocal n_added, bytes_out
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])
if drop_k and arr.ndim == 3:
if arr.shape[2] != 1:
raise ValueError(f"{nemo_name}: expected [out, in, 1], got {arr.shape}")
arr = np.ascontiguousarray(arr[:, :, 0])
writer.add_tensor(gguf_name, arr)
consumed.add(nemo_name)
bytes_out += int(arr.nbytes)
Expand Down Expand Up @@ -2103,6 +2113,7 @@ def add_combined(nemo_a: str, nemo_b: str, gguf_name: str) -> None:
add(
f"encoder.layers.{i}.{suffix_nemo}",
f"enc.blocks.{i}.{suffix_gguf}",
drop_k=suffix_gguf in POINTWISE_2D,
)
# BN running stats only exist when conv_norm_type=batch_norm.
# LayerNorm checkpoints (nemotron-speech-streaming-en-0.6b)
Expand Down