Repository navigation
fix(nemotronh): use a causal attention mask without a cache - #262
Merged
Merged
Conversation
Without a cache, the attention mask of NemotronHModel was .none, so the full forward pass was not causal. The model now builds the mask with or without a cache, as mlx-lm nemotron_h.py does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Implementation
Related issue: #261. Related recording PR: #240 (already integrated on main).
NemotronHBackbone.callAsFunctionpasses the first attention layer's cache, or nil, tocreateAttentionMask(h:cache:). A no-cache multi-token prompt now receives a causal mask; a single token receives no mask. Models without attention still receive no attention mask. Existing CBv2/MTP entry points (cbv2Hidden/cbv2Forward) retain their separate control flow and unchanged semantics.Merged current main
3799b1150699e5595ae4c100a36b1a07cef3c44finto the author branch. Resolvedfork.yamlconflict by retaining both the Nemotron causal-mask topic and current main's DeepSeek pooled-cache / LFM2-MoE topics. Removed the resolved wrapper and matching predicate fromKernel/LLM/NemotronHRuntimeTests, preserving the causality expectation and all controls. Renamed the recording toattentionIsCausalWithAndWithoutACacheand corrected its documentation/references. Author runtime, including its existing formatting, is otherwise unchanged.Before
flowchart LR A["Serial prompt: callAsFunction"] --> B{"Cache supplied?"} B -->|No| C["attentionMask = none"] C --> D["Future tokens affect prefix logits"] B -->|Yes| E["createAttentionMask with cache"] classDef bad fill:#7f1d1d,color:#fff,stroke:#ef4444 class D badAfter
Fresh Validation (2026-10-03)
Owned clone
held-pr-prep-20261003/gen-cache-20261003-gaj, full test products built locally. mlx-swift/core/mlx-c tuple0f4fe403/3fa8f25e/02cf6f4dverified against the immutable reference Metal artifact before staging it only in this clone. GPU executions use the brief's Perl flock wrapper andheld-pr-review-20261002/gpu.lock.1.2534938versus tolerance0.0001. Restored exact author runtime and rebuilt before candidate validation.NemotronHRuntimeTestsand its sibling MTP-row suite, plus the dedicated regression. No stale causal known issue remains.lm262-baseline.log,lm262-candidate.log, and respective build logs in the owned clone. Lint emits only existing uppercase-local naming warnings.Limits And Risk
This corrects generic no-cache Nemotron full-forward behavior. Canonical Nemotron3.5 Lightning serving goes through separate CBv2 paths, exercised here with existing tiny parity tests. An undersized cache list is still invalid input and may trap later in the existing layer loop; this PR does not add short-list support. Full hosted checkpoint/provider qualification, a full test-suite run, and the historical review's 90-cell matrix are not claimed as fresh execution. No dependency revisions, pins, deployment, or admission safeguards changed. Base remains
main; no retarget dependency. Latest-head CI/review gates must be assessed separately.Combined Integration Validation
On 2026-10-03, the current prepared heads of the twelve held PRs were composed
on a local-only validation branch based on main
3799b115, including thesigned-padding compatibility correction
96d5f976. No PR was merged.swift build --build-tests -j 4completed successfully.five optional fixture-dependent XCTest cases skipped. Advanced Arrays/Mamba
and nested signed-padding round trips passed in this composed build.
passed, with no failures or skips, covering paged backend, scheduler,
checkpoint engine, SSM bounds, Nemotron storage/priming, OpenAI service and
tool parser paths.
swift test --skip-build --filter ... --no-parallelunder the shared GPU mutex. This is focused integration validation, not a
full-package, real-weight or provider qualification. Exact compatible MLX
dependency tuple and immutable Metal artifact were verified before staging.
git diff --checkandpython3 scripts/check_forkdiff.pypassed.Existing assertions remain intact; this evidence does not waive required
latest-head CI, review, or parent-first retarget/revalidation gates.