Skip to content

torch.compile compliant transformer decoder + MHA - speed goes vrrrrrrmmmm - #316

Merged
vince62s merged 4 commits into
eole-nlp:mainfrom
vince62s:compiledecoder
Jan 23, 2026
Merged

torch.compile compliant transformer decoder + MHA - speed goes vrrrrrrmmmm#316
vince62s merged 4 commits into
eole-nlp:mainfrom
vince62s:compiledecoder

Conversation

@vince62s

@vince62s vince62s commented Jan 23, 2026

Copy link
Copy Markdown
Contributor

We now have a env-flag EOLE_TORCH_COMPILE
Default is "0": no torch compile, uses the new cuda kernel, gives already x4 speed vs HF transformer "generate"
When set to "1", torch.compile will build the cudagraph for Transformer Decoder and subsequent modules:

  • I need to figure out a better warm up (vLLM like)
  • speed increases another +50% vs cuda kernels.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a torch.compile-oriented path for transformer-decoder inference and refactors several recipe inference scripts to do a warm-up pass before the “real” run.

Changes:

  • Add an EOLE_TORCH_COMPILE env-flag and route decoder forward through a @torch.compile wrapper when enabled.
  • Rework decoder/MHA cache handling to be more compilation-friendly (cache seqlens + scatter-based cache updates, flash-kvcache path).
  • Refactor recipe inference scripts into main() helpers and add a two-pass warm-up + run flow.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
recipes/pixtral/test_inference.py Refactors into helper functions and adds warm-up + actual run passes.
recipes/mistral/test_inference.py Same refactor + warm-up flow for mistral recipe script.
recipes/hunyuanocr/test_inference.py Adds warm-up + actual run pass before printing results.
recipes/gemma3/test_inference.py Refactors into helper functions and adds warm-up + actual run passes.
recipes/deepseekocr/test_inference.py Refactors into helper functions and adds warm-up + actual run passes.
eole/predict/inference.py Threads pos_ids_2d into decoder call and always initializes decoder cache at step 0.
eole/predict/generator.py Disables decoder cache after decoding loop and clears CUDA cache.
eole/predict/init.py Adds torch.compile-related runtime toggles and inductor/dynamo config when enabled.
eole/modules/rope.py Refactors RoPE ops dispatch to a new eole.ops abstraction and updates RoPE update API.
eole/modules/rmsnorm.py Refactors RMSNorm fused op dispatch to eole.ops and gates under torch-compile flag.
eole/modules/multi_headed_attn.py Refactors flash-attn integration + cache update path intended to reduce graph breaks.
eole/encoders/vision.py Updates RoPE update call signature for vision encoder.
eole/encoders/transformer.py Changes encoder to reuse precomputed RoPE embeddings from rope.cos_sin.
eole/decoders/transformer.py Adds compile/eager split, changes cache tracking to cache_seqlens, and updates flash eligibility logic.
eole/decoders/decoder.py Renames cache initializer hook to _init_cache.
eole/constants.py Refactors fused activation dispatch to eole.ops and gates under torch-compile flag.
eole/init.py Introduces EOLE_TORCH_COMPILE env flag.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread eole/decoders/transformer.py
Comment thread eole/decoders/transformer.py
Comment thread eole/decoders/transformer.py Outdated
Comment thread eole/constants.py
Comment thread eole/modules/rope.py
Comment thread eole/modules/multi_headed_attn.py
Comment thread eole/decoders/transformer.py
Comment thread eole/modules/multi_headed_attn.py
Comment thread eole/predict/generator.py
Comment thread eole/modules/rmsnorm.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread eole/decoders/decoder.py Outdated
Comment thread recipes/deepseekocr/test_inference.py
Comment thread eole/modules/multi_headed_attn.py
Comment thread eole/decoders/transformer.py
@vince62s vince62s changed the title Make code torch.compile compliant for the transformer decoder at the … torch.compile compliant transformer decoder + MHA - speed goes vrrrrrrmmmm Jan 23, 2026
@vince62s
vince62s merged commit 5ecde9f into eole-nlp:main Jan 23, 2026
2 checks passed
@vince62s
vince62s deleted the compiledecoder branch March 19, 2026 08:11
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.

2 participants