Skip to content

Migrate DotProductAttention to NNX #2198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hsuan-lun-chiang
Copy link
Collaborator

Description

Migrate DotProductAttention to NNX.

  • Use nnx_wrappers.ToNNX to bridge DotProductAttention, which imported from NVIDIA's transformer library, to NNX.

Tests

Train Gemma-2b with attention=cudnn_flash_te, which use DotProductAttention:

python3 -m MaxText.train  MaxText/configs/base.yml run_name=gpt3-train-run base_output_directory=gs://maxtext-test/gemma-train/18/ max_target_length=128 model_name=gemma-2b dataset_type=synthetic steps=10 hardware=gpu attention=cudnn_flash_te

Logs - After Migration
Logs - Before Migration

Checklist

Before submitting this PR, please make sure (put X in square brackets):

  • I have performed a self-review of my code.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests tests and provided workload links above if applicable.
  • I have made or will make corresponding changes to the doc if needed.

Copy link
Collaborator

@bvandermoon bvandermoon left a comment

Choose a reason for hiding this comment

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

Thank you @hsuan-lun-chiang. Could you check why the GPU integration test is failing?

Comment on lines +551 to +563
dummy_query_prefill = jnp.zeros((1, self.max_target_length, self.num_query_heads, config.head_dim), dtype=self.dtype)
dummy_key_prefill = jnp.zeros((1, self.max_target_length, self.num_kv_heads, config.head_dim), dtype=self.dtype)
dummy_value_prefill = jnp.zeros((1, self.max_target_length, self.num_kv_heads, config.head_dim), dtype=self.dtype)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@cgarciae are zeros the right value here?

@hsuan-lun-chiang hsuan-lun-chiang force-pushed the feat/Migrate-DotProductAttention-to-NNX branch from bd06740 to 16ad76e Compare August 19, 2025 05:24
@hsuan-lun-chiang
Copy link
Collaborator Author

Thank you @hsuan-lun-chiang. Could you check why the GPU integration test is failing?

Sure! It was causes by None being casting to uint8, fixed it. Thank you.

Copy link
Collaborator

@bvandermoon bvandermoon left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you @hsuan-lun-chiang. Did you run the description test on a GPU VM? Let's get @cgarciae's thoughts as well

@hsuan-lun-chiang
Copy link
Collaborator Author

LGTM. Thank you @hsuan-lun-chiang. Did you run the description test on a GPU VM? Let's get @cgarciae's thoughts as well

Happy to help! Yes, I ran the test on a GPU VM with A100 80GB.

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