Skip to content

[Executorch][llama] Hookup use_attention_mask option in the source transforms inside llm mananger #10286

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

Merged
merged 4 commits into from
Apr 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion examples/models/llama/export_llama_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,10 +1227,22 @@ def _get_source_transforms( # noqa
if args.expand_rope_table:
transforms.append(materialze_broadcast_of_rope_freq_cis)

use_attention_mask_for_custom_sdpa = False
if isinstance(args, argparse.Namespace):
if getattr(args, "use_custom_sdpa_with_attention_mask", None):
use_attention_mask_for_custom_sdpa = True

if args.use_sdpa_with_kv_cache:
transforms.append(replace_kv_cache_with_custom_kv_cache)
# todo: do this optionally
transforms.append(replace_sdpa_with_custom_op)
# if use attention mask instead of causal attention
# then create partial function that sets use_attention_mask=True
if use_attention_mask_for_custom_sdpa:
transforms.append(
partial(replace_sdpa_with_custom_op, use_attention_mask=True)
)
else:
transforms.append(replace_sdpa_with_custom_op)

if args.quantize_kv_cache:
assert args.use_kv_cache, "quantize_kv_cache requires use_kv_cache=True"
Expand Down
Loading