Skip to content

Add support for GigaAM-v4 (Zapformer encoder + RNN-T) #279

Done

Description

@70sh1

Proposing support for ai-sage/GigaAM-v4 (Zapformer encoder + RNN-T).

  • Upstream model repo: https://huggingface.co/ai-sage/GigaAM-v4
  • Proposed family key: gigaam (reusing the existing family with stt.gigaam.encoder.type = "zapformer" — open to a separate family key if preferred)
  • Variants: gigaam-v4-e2e-rnnt (cased/punctuated RU+EN, 1024 SentencePiece) and gigaam-v4-raw-rnnt (raw/unpunctuated head in the same checkpoint)
  • Architecture pattern: encoder-transducer

Notes

GigaAM-v4 keeps the same 64-mel frontend and 1-layer LSTM + ReLU Joint RNN-T decoder as GigaAM-v3, but replaces the 16-layer Conformer with a 3-stage 4/11/4 Zapformer (768/1024/768 dims, 2x frame stacking/unstacking in stage 1, causal Conv2d + ConvNeXt frontend, interleaved RoPE base 10000, gated flash attention, depthwise conv + global mean branch + SiLU, final RmsNorm).

I already put together a local working prototype and F32 GGUF converter (based on 0.4.1 while testing with Hex; prototype code was built with AI assistance and checked locally):

  • Reuses existing transcribe-quantize policy with no changes (e2e head: 912 MB F32 -> 243 MB Q8_0).
  • Matches PyTorch GigaAMDualASR encoder output on odd-length audio (T_enc=113: max_abs = 0.00057, cosine 1.000000) and matches transcripts character-for-character across 6 RU/EN clips (including a 33.8s windowed clip) on CPU and Metal (F32 and Q8_0).
  • Runs ~45x–132x realtime on Apple M4 Metal Q8_0.

If you'd like this upstream, I can rebase it onto main, follow the docs/porting/ checklist (intake, preflight A/B, golden manifest/tolerances, clang-format, smoke tests), and open a PR. Before starting, would you prefer keeping this under the gigaam family (stt.gigaam.encoder.type = "zapformer") or splitting it into a new family key?

Prototype & candidate GGUFs (review artifacts)

  • Branch: https://github.com/70sh1/transcribe.cpp/tree/gigaam-v4 (commit 4d860cd81b0b4cf89973d14e6a42d8891ca47f81, based on 0.4.1 fork)
  • Candidate GGUFs: https://huggingface.co/70sh1/gigaam-v4-e2e-rnnt-gguf
  • Source revision: ai-sage/GigaAM-v4 @ 180301a192bb45bc2b2ca122e0d4aab24ffe7a96
  • Conversion / quantization: scripts/convert-gigaam-v4.py <snapshot> gigaam-v4-e2e-rnnt-F32.gguf --head e2e, then transcribe-quantize --quant Q8_0
  • SHA256:
    • gigaam-v4-e2e-rnnt-Q8_0.gguf: debd6179b9948beba5c60c0944285e577f32610dd50dee1233884e4b46e3e29
    • gigaam-v4-e2e-rnnt-F32.gguf: 6cd32ae7ded4ec470075ac7acb79c248b64818f118c6913a96c4a81ae11cd745

Activity

  1. kalpakprod commented on Nov 28, 2026

    @kalpakprod
    Contributor

    Thanks for the Zapformer port. Your v4 GGUF runs unchanged in wavo, which I've added Zapformer to (wavo PR).

    I extended convert-gigaam-v4.py for GigaAM-Multilingual-v2: its Swish activations (written to stt.gigaam.encoder.activation, which stays absent for SiLU) and its language conditioning (stt.gigaam.language.codes, embedding_dim and film_layers, plus the tensors lang.embed, lang.film.N and lang.fusion.*). The late-fusion weight is split into the frames part and the language part, so a runtime can fold the language into the bias. On v4 the extended converter writes your file byte for byte. Feel free to take any of it into the PR you offered to open.

    The diff against convert-gigaam-v4.py at 4d860cd
    --- a/scripts/convert-gigaam-v4.py
    +++ b/scripts/convert-gigaam-v4.py
    @@ -1,5 +1,9 @@
     #!/usr/bin/env python3
    -"""convert-gigaam-v4.py - convert an ai-sage/GigaAM-v4 checkpoint directory
    +"""convert-zapformer.py - convert an ai-sage GigaAM Zapformer checkpoint (GigaAM-v4 or
    +GigaAM-Multilingual-v2) directory. Based on convert-gigaam-v4.py of 70sh1/transcribe.cpp@4d860cd
    +(MIT); adds the Swish activations and the language conditioning of Multilingual-v2.
    +
    +Original description: convert an ai-sage/GigaAM-v4 checkpoint directory
     (model.safetensors + config.json + {e2e,raw}_tokenizer.model) into a GGUF
     for transcribe.cpp's Zapformer GigaAM backend.
     
    @@ -92,7 +96,10 @@
         sd = load_file(str(st_path))
         sd_keys = set(sd.keys())
     
    +    seen: set[str] = set()
    +
         def get_f32(key: str) -> np.ndarray:
    +        seen.add(key)
             if key not in sd:
                 raise KeyError(f"missing tensor {key!r}")
             return np.ascontiguousarray(sd[key].astype(np.float32))
    @@ -108,9 +115,10 @@
         stage_conv_kernel = parse_int_list(enc_cfg["conv_params"])
         stage_downsampling = parse_int_list(enc_cfg["downsampling_factor"])
         causal_frontend = bool(enc_cfg.get("causal_frontend", True))
    -    activation = str(enc_cfg.get("activation", "SiLU")).lower()
    -    if activation != "silu":
    -        raise ValueError(f"unsupported Zapformer activation {activation!r} (only SiLU implemented)")
    +    activation = str(enc_cfg.get("activation", "swish")).lower()
    +    if activation not in ("silu", "swish"):
    +        raise ValueError(f"unsupported Zapformer activation {activation!r}")
    +    lang_cfg = cfg.get("language_conditioning")
     
         feat_in = int(enc_cfg["in_channels"])
         d_model = stage_dims[0]
    @@ -157,8 +165,9 @@
         fb = np.ascontiguousarray(get_f32("model.preprocessor.featurizer.0.mel_scale.fb").T)
         window = get_f32("model.preprocessor.featurizer.0.spectrogram.window")
     
    -    variant = f"gigaam-v4-{head}-rnnt"
    -    display_name = f"GigaAM v4 {'E2E' if head == 'e2e' else 'Raw'}-RNN-T"
    +    slug = repo_id.rsplit("/", 1)[-1].lower()
    +    variant = f"{slug}-{head}-rnnt"
    +    display_name = f"{repo_id.rsplit('/', 1)[-1].replace('-', ' ')} {'E2E' if head == 'e2e' else 'Raw'}-RNN-T"
     
         # Compute parameter count for size_label (encoder + selected head)
         total_params = sum(
    @@ -166,6 +175,7 @@
             for k in sd_keys
             if (k.startswith("model.encoder.") and "rope_bank" not in k)
             or k.startswith(f"model.heads.{head}.")
    +        or k.startswith("model.language_")
         )
         size_label = f"{total_params / 1_000_000:.0f}M"
         print(f"Converting {variant} ({total_params:,} params -> {size_label}) -> {out_path}")
    @@ -176,11 +186,11 @@
         add_general_identity(
             writer,
             name=display_name,
    -        basename="gigaam-v4",
    +        basename=slug,
             size_label=size_label,
    -        version="v4",
    +        version=slug.rsplit("-", 1)[-1],
             file_type=LlamaFileType.ALL_F32,
    -        languages=["ru", "en"],
    +        languages=list(lang_cfg["languages"]) if lang_cfg else ["ru", "en"],
             author="Salute Developers",
             organization="ai-sage",
             license="mit",
    @@ -210,6 +220,9 @@
     
         # Zapformer encoder metadata
         writer.add_string("stt.gigaam.encoder.type", "zapformer")
    +    # SiLU is the default: a GigaAM-v4 file stays the one convert-gigaam-v4.py writes.
    +    if activation != "silu":
    +        writer.add_string("stt.gigaam.encoder.activation", activation)
         writer.add_uint32("stt.gigaam.encoder.n_layers", sum(stage_layers))
         writer.add_uint32("stt.gigaam.encoder.d_model", d_model)
         writer.add_uint32("stt.gigaam.encoder.feat_in", feat_in)
    @@ -358,6 +371,37 @@
         add(f"{hpfx}.joint.joint_net.1.weight", "joint.out.weight")
         add(f"{hpfx}.joint.joint_net.1.bias", "joint.out.bias")
     
    +    # 5. Language conditioning (Multilingual-v2): embedding slots (0 = auto, i + 1 = languages[i]),
    +    # FiLM after every n-th layer (global layer index), late-fusion MLP after the encoder.
    +    if lang_cfg:
    +        film = lang_cfg["film"]
    +        if film.get("placement", "every_n") != "every_n" or not film.get("enabled", True):
    +            raise ValueError(f"unsupported FiLM placement {film!r}")
    +        fusion = lang_cfg["late_fusion"]
    +        if not fusion.get("enabled", True) or fusion.get("fusion") != "mlp" or fusion.get("activation") != "relu":
    +            raise ValueError(f"unsupported late fusion {fusion!r}")
    +        writer.add_array("stt.gigaam.language.codes", list(lang_cfg["languages"]))
    +        writer.add_uint32("stt.gigaam.language.embedding_dim", int(lang_cfg["embedding_dim"]))
    +        film_layers = sorted(int(k.split(".")[-2]) for k in sd_keys if k.startswith("model.encoder.language_film.projections.") and k.endswith(".weight"))
    +        writer.add_array("stt.gigaam.language.film_layers", film_layers)
    +        add("model.language_embedding.weight", "lang.embed.weight")
    +        for i in film_layers:
    +            add(f"model.encoder.language_film.projections.{i}.weight", f"lang.film.{i}.weight")
    +            add(f"model.encoder.language_film.projections.{i}.bias", f"lang.film.{i}.bias")
    +        # The first fusion layer over concat(frames, embedding), split by input: the frames' part
    +        # stays a quantized linear layer, the embedding's (tiny) folds into its bias at load.
    +        w0 = get_f32("model.language_fusion.kernel.0.weight")
    +        e = int(lang_cfg["embedding_dim"])
    +        add_arr("lang.fusion.0.weight", w0[:, :-e])
    +        add_arr("lang.fusion.0.emb.weight", w0[:, -e:])
    +        add("model.language_fusion.kernel.0.bias", "lang.fusion.0.bias")
    +        add("model.language_fusion.kernel.3.weight", "lang.fusion.1.weight")
    +        add("model.language_fusion.kernel.3.bias", "lang.fusion.1.bias")
    +
    +    skipped = {k for k in sd_keys if "rope_bank" in k or k.startswith("model.heads.") and not k.startswith(f"model.heads.{head}.")}
    +    unused = sorted(sd_keys - seen - skipped)
    +    if unused:
    +        raise ValueError(f"{len(unused)} checkpoint tensors not converted, e.g. {unused[:5]}")
         print(f"Added {n_added} tensors ({bytes_out / (1024 * 1024):.1f} MB)")
         writer.write_header_to_file()
         writer.write_kv_data_to_file()
    @@ -371,7 +415,7 @@
         p.add_argument("model_dir", type=Path, help="Directory with model.safetensors, config.json, *_tokenizer.model")
         p.add_argument("out_path", type=Path, help="Output .gguf path")
         p.add_argument("--head", choices=("e2e", "raw"), default="e2e", help="RNN-T head to export (default: e2e)")
    -    p.add_argument("--repo-id", default="ai-sage/GigaAM-v4", help="Upstream HF repo id for metadata")
    +    p.add_argument("--repo-id", required=True, help="Upstream HF repo id for metadata and the variant name")
         args = p.parse_args(argv[1:])
         convert(args.model_dir, args.out_path, args.head, args.repo_id)
         return 0
  2. yura0148 commented on Nov 28, 2026

    @yura0148

    Interested in GigaAM-v4 (e2e-rnnt) upstream for Russian/English dictation on Windows + CUDA (transcribe.cpp 0.5.x). Happy to test Windows/CUDA builds once a PR is opened.

  3. nikita-ashihmin commented on Nov 29, 2026

    @nikita-ashihmin
    Contributor

    @70sh1 thanks for the port. I needed v4 for Handy, so I ran your branch through the porting checklist on top of current main and opened a PR: #285. Your Zapformer commit is in it as is (cherry-picked, authorship kept). On top of it:

    • a PyTorch reference built from modeling_gigaam.py at 180301a1 in its own env (the pinned gigaam package has no Zapformer), golden manifest, tolerances, enc.stage.<s>.out dumps, smoke test, intake and porting log, reference WER runner
    • long-form windows now start on an even frame, so the half-rate stack pairs the same frames as whole-clip inference
    • loader checks for stage geometry, and Zapformer batches skip the unused batch mel pass

    validate.py all is green on ru (odd T_enc) and fleurs-en, preflight B passes, and the converter output is byte-identical to your F32/Q8_0 GGUFs. FLEURS WER: PyTorch 4.34% ru / 4.92% en, C++ F32 4.35% / 4.92%.

    Since you offered to open the PR yourself, tell me how you'd prefer to go: keep #285 and review it, or take whatever is useful into your own branch and I'll close mine. The gigaam vs separate family key question is still open for the maintainers; I kept gigaam as in your branch.

    @yura0148 a Windows/CUDA run of #285 would help, I only tested CPU and Metal.

  4. 70sh1 commented on Nov 29, 2026

    @70sh1
    ContributorAuthor

    @nikita-ashihmin

    Feel free to continue the necessary work within your own PR (#285), I won't take it over for now.

  5. cjpais commented on Dec 3, 2026

    @cjpais
    Contributor

    This is supported and merged now, It'll be in the next release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions