Skip to content

Conversation

@LoserCheems
Copy link
Collaborator

Simplify the CUDA interface by replacing direct module imports with a higher-level function that uses named parameters. Enhance usability by removing manual tensor preparation and adding runtime checks for CUDA availability before executing tests.

Replaces direct CUDA module import with higher-level interface function that provides cleaner API with named parameters.

Simplifies function call by removing manual tensor preparation and using more intuitive parameter names like dropout_p and softmax_scale.

Adds runtime check to ensure CUDA implementation availability before executing tests.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Refactor the CUDA interface to use a higher-level function with named parameters instead of direct module imports. The changes simplify tensor preparation by removing manual contiguous() calls and improve error handling with runtime checks for CUDA availability.

  • Replace direct flash_dmattn_cuda module import with flash_dmattn_func from interface module
  • Simplify CUDA function call using named parameters instead of positional arguments
  • Add runtime checks for CUDA availability before executing tests

Comment on lines +248 to +250
query_states = query_states.transpose(1, 2) # [batch, query_len, num_heads, head_dim]
key_states = key_states.transpose(1, 2) # [batch, key_len, num_kv_heads, head_dim]
value_states = value_states.transpose(1, 2) # [batch, key_len, num_kv_heads, head_dim]
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

Removing .contiguous() calls may cause performance issues if the tensors are not contiguous in memory. CUDA kernels typically require contiguous tensors for optimal performance. Consider adding .contiguous() back or verify that the new interface handles non-contiguous tensors efficiently.

Suggested change
query_states = query_states.transpose(1, 2) # [batch, query_len, num_heads, head_dim]
key_states = key_states.transpose(1, 2) # [batch, key_len, num_kv_heads, head_dim]
value_states = value_states.transpose(1, 2) # [batch, key_len, num_kv_heads, head_dim]
query_states = query_states.transpose(1, 2).contiguous() # [batch, query_len, num_heads, head_dim]
key_states = key_states.transpose(1, 2).contiguous() # [batch, key_len, num_kv_heads, head_dim]
value_states = value_states.transpose(1, 2).contiguous() # [batch, key_len, num_kv_heads, head_dim]

Copilot uses AI. Check for mistakes.
attn_mask = attn_mask.contiguous() # [batch, num_kv_heads, query_len, key_len]
query_states = query_states.transpose(1, 2) # [batch, query_len, num_heads, head_dim]
key_states = key_states.transpose(1, 2) # [batch, key_len, num_kv_heads, head_dim]
value_states = value_states.transpose(1, 2) # [batch, key_len, num_kv_heads, head_dim]
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

The zoh_states calculation and expansion logic has been removed, but the calculate_zoh_states function is still called earlier in the function. This may cause the attention mechanism to not work correctly as zoh_states appear to be required for the dynamic mask attention computation.

Copilot uses AI. Check for mistakes.
@LoserCheems LoserCheems merged commit 4e93039 into main Jul 30, 2025
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.

5 participants