Pass target context as ctx_other so Gemma4 E4B MTP can init - #92
Merged
Merged
Conversation
gemma4-assistant requires llama_context_params.ctx_other at draft construction; Qwen still works when the option is omitted (nullptr).
Owner
|
Thanks @dai-yamashita — this is the right fix, and it matches upstream exactly: |
nyo16
added a commit
that referenced
this pull request
Sep 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #91.
Why
MTP.init/2already accepts a sidecar:draft_model(#86). That is enough for Qwen 3.8. It is not enough for Gemma4 E4B.gemma4-assistantrequiresllama_context_params.ctx_otherat draft context construction — shared KV and the target's token embeddings. llama.cpp throws if the pointer is missing:Context.create/2never exposed the field. The NIF starts fromllama_context_default_params(), soparams.ctx_otherstayednullptr. Qwen's constructor leavescparams.ctx_otherasnullptr, which is why the existing sidecar path stayed green.Creating a draft context on the assistant GGUF without a target still fails. That is llama.cpp's contract.
What changed
Context.create/2takes optional:ctx_other. The NIF copies the rawllama_context*intoparams.ctx_otherand Fine-keeps the peer so the target cannot be collected while the draft still holds the pointer.MTP.init/2always passes the target as the draft's:ctx_other. Callers do not set it. Qwen ignores it; Gemma4 needs it.Same
:draft_modelAPI as Qwen 3.8. The only new requirement is the peer pointer on the draft.:mtp_sidecargained a second fixture pair behindLLAMA_SMOKE_MTP_E4B_MODEL/LLAMA_SMOKE_MTP_E4B_DRAFT_MODEL. Unset vars skip that module, so--include mtp_sidecarwith only the Qwen pair stays green.Model.n_embd_out/1docs now note thatgemma4-assistanthas a narrown_embdand a widen_embd_out. The existing hidden-width guard still comparesn_embd_out.No
@versionbump. The forkmix.exsis still0.8.43.Measured
Unsloth
gemma-4-E4B-it-Q4_K_M.gguf(4_971_171_584 B) +mtp-gemma-4-E4B-it-Q8_0.gguf(98_653_248 B), M3 Ultra, Metal, 2026-09-12:0.8.48:MTP.init/2fails with thectx_otherthrow above.MTP.init/2returns a session;generateis non-empty;timing_us.ckpt == 0(E4B is dense, not hybrid).Context.create(head)without a target still fails. Expected.I did not re-run the Qwen 3.8 sidecar matrix. The NIF default remains omitted →
nullptr.Deliberately not changed
ggml_metal_device_free(GGML_ASSERT([rsets->data count] == 0)). That is teardown, not init. Explain the Metal teardown abort and disable residency sets in smoke runs #78 already documents it. Not this PR.--spec-defaultstays unreachable. Same as MTP: separate sidecar draft model, llama.cpp b10435 (Qwen 3.8) #86.Verification
Default suite (no model) plus the new guards:
Context.create/2rejects a non-%Context{}:ctx_otherctx_other: nilis the omit path%Context{}carries the peer resource it was built fromOptional E4B gate (skips when unset):
Qwen-only
--include mtp_sidecaris unchanged:MTPSidecarTeststill requiresLLAMA_SMOKE_MTP_MODEL+LLAMA_SMOKE_MTP_DRAFT_MODEL.Review notes
LlamaContext.ctx_otheris load-bearing for Gemma4. Qwen drops the C pointer, but the Elixir peer field is still set so the resource graph is the same for both architectures.@version. Happy to add a changelog/release-guide note if you want this in 0.8.49.