Skip to content

Add Qwen3.6-27B hybrid DeltaNet/GQA contrib model and vLLM serving path - #173

Open
m-deepankar-singh wants to merge 4 commits into
aws-neuron:mainfrom
m-deepankar-singh:qwen36-27b-contrib-clean
Open

Add Qwen3.6-27B hybrid DeltaNet/GQA contrib model and vLLM serving path#173
m-deepankar-singh wants to merge 4 commits into
aws-neuron:mainfrom
m-deepankar-singh:qwen36-27b-contrib-clean

Conversation

@m-deepankar-singh

Copy link
Copy Markdown

Summary

This adds a Qwen3.6-27B contrib implementation for NxDI. Qwen3.6-27B is not a standard transformer-only decoder; it uses a hybrid [3 DeltaNet + 1 GQA] x 16 architecture with 48 recurrent DeltaNet/GDN layers and 16 GQA layers. Supporting it requires model code, DeltaNet NKI kernels, hybrid recurrent-state cache handling, vLLM/OpenAI serving glue, and validation coverage.

The main additions are:

  • Qwen3.6/Qwen3.5-compatible model implementation under contrib/models/Qwen3.6-27B/.
  • DeltaNet/GDN NKI kernels for token generation and chunked context encoding.
  • Hybrid cache/APC support for matching attention KV reuse with GDN recurrent and convolution state checkpoints.
  • Selective FP8 path for long-context serving while keeping sensitive recurrent state/cache paths in BF16/FP32.
  • vLLM Neuron registry/launcher/proxy helpers and OpenAI-compatible validation scripts.
  • Unit, integration, and artifact audit coverage for model config, weight conversion, Hybrid APC/cache semantics, scheduler behavior, and serving correctness.

Why this is larger than a normal contrib model

Stock NxDI has the standard serving substrate for transformer models, but Qwen3.6-27B needs additional hybrid recurrent-state semantics. Attention KV prefix reuse alone is insufficient. A safe reusable prefix is the intersection of attention KV cache hits, GDN recurrent checkpoint hits, and GDN convolution checkpoint hits. The PR therefore includes the minimal scheduler/model/cache bridge needed for coherent long-context Hybrid APC.

Validation

Recorded on trn2.3xlarge, TP=4, LNC=2. Evidence committed under validation_outputs/qwen36_nativechunk_baseline_20260609T000000Z/.

  • 256K coherent native-chunk baseline, locally verified:
    • 16K native-chunk run: 16,374 prompt tokens, 6.84 s TTFT, 2,394.6 tok/s usage-accounted, pass=true, thinking enabled.
    • Long-context run: 242,864 usage.prompt_tokens, 235.98 s TTFT, 1,029.2 tok/s usage-accounted, pass=true, thinking enabled.
    • Empty invalid-token/fallback/NaN/NRT/traceback log scan; summary marks the run coherent and target-recovered.
  • Correctness checks:
    • BF16 quality smoke: 7/7 prompts passed with enable_thinking=False.
    • HF greedy comparison: 156/160 token positions matched HF greedy (97.5%); 9/10 prompts matched exactly for all 16 generated tokens.
    • Strict Hybrid APC exactness passed for full-prefix, partial-prefix, and real-token generation cases.

Known limitations and follow-ups

  • Continuous batching past max_num_seqs=1 is not included in this baseline.
  • Some 32K/64K APC validation requires a recompiled artifact with larger prefix bucket coverage.
  • Native Qwen MTP speculative decoding is not included.
  • The stable direct-solve DeltaNet path trades some decode throughput for numerical stability versus the faster Neumann-style path.

Tests

  • CPU unit tests for config parsing, weight conversion, Hybrid APC/cache behavior, DeltaNet decay, scheduler behavior, and artifact config audit.
  • Integration test path (test/integration/test_model.py) for model load/generation/coherence on trn2.3xlarge.
  • OpenAI/vLLM validation scripts for cold prefill, decode, APC exactness, boundary probes, and memory capture.

🤖 Generated with Claude Code

m-deepankar-singh and others added 3 commits June 10, 2026 22:39
Clean-room cut of codex/nki-deltanet-multihead-cte (43ca740) onto upstream main:
contrib model + NKI kernels, hybrid APC/GDN cache support, core substrate,
unit tests, validation scripts, and the verified nativechunk baseline evidence.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…decode throughput

Pull hardware validation artifacts into validation_outputs/ (were on the trn2
host but not the repo): HF greedy match (156/160, 97.5%, 9/10 exact), Hybrid APC
exactness (full/partial-prefix self-consistency), decode throughput summary, and
a fresh live decode sweep (2026-06-11).

README corrections and additions:
- Fix fused-kernel description: direct blocked triangular solve (exact per-block
  power-doubling), not a Neumann series (the legacy chunked kernel used Neumann).
- Scope "256K coherent" to prefill + first-token coherence (16 completion
  tokens), not sustained long-form generation.
- Cite the HF-match and APC-exactness artifacts with honest caveats (APC exactness
  is cache-reuse self-consistency; fault-injection negatives not yet automated).
- Add Decode Throughput section: ~7.5 tok/s batch=1, near-flat across context (the
  hybrid O(1)-state signature); note a speed-optimized artifact logged ~30-35
  tok/s pending a coherence gate, with on-device sampling as the largest lever.
- Bump Last Updated to 2026-06-11.

Add validation_scripts/qwen36_live_decode_sweep.py (reusable live decode bench).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
srechase-aws pushed a commit that referenced this pull request Jul 28, 2026
Qwen3.5-2B is a 2B-parameter image-text-to-text decoder with a hybrid
attention stack: 24 layers arranged as [3 gated DeltaNet + 1 full GQA] x 6.
Adapts the modeling code contributed by PR #173 (Qwen3.6-27B sibling,
which shares model_type=qwen3_5) to the 2B variant.

Key deltas vs the 27B code:
- Add update_state_dict_for_tied_weights (2B ties embed_tokens<->lm_head; 27B
  does not).
- Fallback shims for cancel/finish/prepare_hybrid_apc_request so the module
  loads on stock NxDI SDK 2.29 (those symbols are only exported by the
  unmerged PR #173 branch; hybrid APC is disabled by default anyway).
- VL generate output parsing: read tokens off CausalLMOutputWithPast.tokens
  when on_device_sampling is enabled (logits is None in that mode).
- Pad vision_embeddings / vision_mask / mRoPE position_ids to the CTE
  bucket size instead of the raw input length.

Validated on trn2.48xlarge (TP=8, bf16, seq_len=512):
- TTFT ~17.6 ms, TPOT ~4.0 ms (250 tok/s) across prompt lengths 16-256.
- 3/5 prompts fully match HF transformers 5.13 CPU greedy (16/16 tokens);
  66% aggregate token-match rate.
- End-to-end VL path runs on a real image via CPU-side ViT + Neuron text
  decoder.

Runs on stock /opt/aws_neuronx_venv_pytorch_2_9_nxd_inference/ with no
library modifications.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
srechase-aws pushed a commit that referenced this pull request Jul 28, 2026
The VL orchestrator copied from PR #173 is not verified upstream. When
wired end-to-end here it produces degenerate output (repeated token) on real
images even though each component works in isolation:
  - CPU vision encoder: cosine 0.99 vs HF Qwen3_5VisionModel on a real image
  - get_rope_index: 100% token-position match vs HF compute_3d_position_ids
  - Text decoder compiles cleanly with use_text_only_cte_inputs=False

The remaining gap is in the vision-scatter path inside the traced graph.
Root cause is not yet isolated — likely candidates: the
has_real_vision_inputs = shape[1] != seq_length gate in
NeuronQwen35Model.get_model_output (~L5747), the padded_seq_len-1 fill for
vision_mask pad slots (which overwrites a real text token position with
vision garbage), or an interaction with the DeltaNet deltanet_padding_mask.

README updated to prominently flag VL as WIP and list the debug pointers.
Also drops one now-inaccurate comment in run_vl_smoke's pad section.

No changes to text-only path (still: TTFT ~17.6 ms, TPOT ~4.0 ms, 3/5
prompts fully match HF greedy).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
srechase-aws pushed a commit that referenced this pull request Jul 28, 2026
Qwen/Qwen3.5-35B-A3B is the MoE flagship of the qwen3_5 family — 35 B total
params, ~3 B activated per token via top-8 routing over 256 experts plus a
sigmoid-gated shared expert. Same hybrid attention stack as the dense
siblings: [3 gated DeltaNet + 1 full GQA] × 10 = 40 layers, head_dim=256,
partial_rotary_factor=0.25, mrope_section=[11,11,10]. Uniquely: model_type
is qwen3_5_moe_text (not qwen3_5_text), no dense intermediate MLP, and every
layer's MLP is a sparse MoE with 256 experts (moe_intermediate_size=512)
plus a shared expert with a per-token sigmoid gate.

This is the FIRST DeltaNet + MoE integration on Neuron; upstream NxDI ships
a Qwen3-MoE (dense-attention MoE) reference and PR #173 provides
DeltaNet+dense, but nothing combines the two. The MoE plumbing wraps NxDI's
initialize_moe_module (moe_v2) inside a new Qwen35MoEBlock and adds a
sigmoid-gated shared expert on top (NxDI's built-in SharedExperts only sums).

Modeling deltas vs dense-2B/4B/9B/27B:
- Qwen35InferenceConfig.from_pretrained preserves model_type (was hardcoded
  qwen3_5_text) so qwen3_5_moe_text is detected.
- Qwen35InferenceConfig.__init__ auto-populates num_local_experts,
  n_shared_experts=1, and maps moe_intermediate_size → intermediate_size.
- New Qwen35MoEBlock: routed experts via initialize_moe_module + per-token
  sigmoid-gated shared expert (SwiGLU MLP + sigmoid gate).
- NeuronQwen35DecoderLayer routes MLP to Qwen35MoEBlock when _is_moe=True.
- convert_qwen35_hf_to_neuron_state_dict transposes stacked expert weights
  (HF: (E, 2I, H) / (E, H, I) → NxDI: (E, H, 2I) / (E, I, H)) and renames
  mlp.gate.weight, mlp.experts.*, mlp.shared_expert.*_proj.weight to the
  NxDI convention (moe.router.linear_router.weight,
  moe.expert_mlps.mlp_op.gate_up_proj.weight etc, shared_gate_proj etc).

Text-only validated on trn2.48xlarge, TP=8, bf16, seq_len=512:

    prompt tokens   TTFT (ms)   TPOT (ms)   tok/s
    16              553.8       7.67        129.9
    64              554.0       7.79        128.2
    256             553.6       7.74        129.2

Outputs on 5 prompts all qualitatively correct and coherent:
  "The capital of France is Paris."
  "Jupiter is a gas giant..."
  "Water boils at 100°C."
  autumn haiku ("Crimson drifts down slow, Golden carpet ...")
  photosynthesis definition.

Notable runtime knobs (set automatically by the runner scripts):
- MoENeuronConfig with moe_tp_degree=8, moe_ep_degree=1
- blockwise_matmul_config.use_torch_block_wise=True — the DLAMI ships no
  LNC=2 shard-hidden NKI kernel; torch fallback is functionally correct
  but slower.
- router_config.dtype=fp32, router_config.act_fn=softmax,
  normalize_top_k_affinities=True.
- shared_expert_gate uses plain nn.Linear (scalar output; can't shard).

VL not attempted in this contrib — see README follow-ups. HF greedy match
also deferred (67 GB CPU bf16 is prohibitively slow).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant