Skip to content

[KernelGen][Nvidia] Add _flash_attention_forward_no_dropout_inplace operator with Triton kernel - #5545

Open
chx7514 wants to merge 3 commits into
flagos-ai:masterfrom
chx7514:pr/_flash_attention_forward_no_dropout_inplace
Open

[KernelGen][Nvidia] Add _flash_attention_forward_no_dropout_inplace operator with Triton kernel#5545
chx7514 wants to merge 3 commits into
flagos-ai:masterfrom
chx7514:pr/_flash_attention_forward_no_dropout_inplace

Conversation

@chx7514

@chx7514 chx7514 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a Triton kernel for _flash_attention_forward_no_dropout_inplace. Triton kernel implementation for _flash_attention_forward_no_dropout_inplace.
A specialised variant of _flash_attention_forward that drops the dropout
argument (implicitly dropout_p=0.0) and writes the attention output in-place.

Testing

  • Validated against reference on device via to_reference(inp, True)
  • Tested on: Nvidia, Tianshu, Muxi, Ascend, Hygon

Performance

Test command: pytest benchmark/test_flash_attention_forward_no_dropout_inplace.py --level core (NVIDIA H20)

flash_attention_forward_no_dropout_inplace

dtype Size Torch Latency (ms) Gems Latency (ms) Speedup
float16 [1, 512, 2, 64] 0.016736 0.071936 0.233
float16 [1, 1024, 8, 128] 0.072640 0.075168 0.966
float16 [2, 512, 4, 64] 0.021408 0.078592 0.272
float16 [1, 1024, 2, 64] 0.028288 0.075152 0.376
bfloat16 [1, 512, 2, 64] 0.015776 0.072800 0.217
bfloat16 [1, 1024, 8, 128] 0.072480 0.077184 0.939
bfloat16 [2, 512, 4, 64] 0.021216 0.073952 0.287
bfloat16 [1, 1024, 2, 64] 0.028320 0.076256 0.371
Operator Geometric Mean Speedup
flash_attention_forward_no_dropout_inplace 0.387

Multi-backend Testing

Backend Accuracy Test Speedup (mean) Notes
Nvidia (H20) PASS (8 cases) 0.387 Primary
Tianshu N/A
Muxi N/A
Ascend N/A
Hygon N/A

Files Changed

  • src/flag_gems/ops/_flash_attention_forward_no_dropout_inplace.py: Triton kernel implementation
  • tests/test_flash_attention_forward_no_dropout_inplace.py: Accuracy test
  • benchmark/test_flash_attention_forward_no_dropout_inplace.py: Performance benchmark
  • src/flag_gems/ops/__init__.py: Register import and __all__
  • src/flag_gems/__init__.py: Register to _FULL_CONFIG
  • conf/operators.yaml: Add operator entry (kind: NeuralNetwork, stage: alpha 5.4)

@chx7514
chx7514 force-pushed the pr/_flash_attention_forward_no_dropout_inplace branch from fcc9a39 to dcf70a0 Compare August 17, 2026 06:58

# In-place semantics: the result is written back into ``query``.
query.copy_(out)
return query, lse, philox_seed, philox_offset, debug_attn_mask

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could this be implemented by adding a new interface in flash_api only, without introducing a new operator interface?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants