Skip to content

[FA4] Add kernels fallback#44797

Draft
vasqu wants to merge 1 commit intohuggingface:mainfrom
vasqu:fa4-kernel-fallback
Draft

[FA4] Add kernels fallback#44797
vasqu wants to merge 1 commit intohuggingface:mainfrom
vasqu:fa4-kernel-fallback

Conversation

@vasqu
Copy link
Contributor

@vasqu vasqu commented Mar 17, 2026

Draft for now because we probably want this in the main kernels-community

But it works OOB with little changes! Example script for demonstration:

from transformers import AutoModelForCausalLM, AutoTokenizer


fa_version = 4
#model_id = "openai/gpt-oss-20b"
model_id = "meta-llama/Llama-3.2-3B-Instruct"


model = AutoModelForCausalLM.from_pretrained(
    model_id,
    device_map="auto",
    attn_implementation=f"flash_attention_{fa_version}",
).eval()
tokenizer = AutoTokenizer.from_pretrained(model_id)
tokenizer.pad_token = tokenizer.eos_token
inputs = tokenizer(
    ["Hello, how are you?", "How are you? Tell me the name of the president of"],
    padding=True,
    padding_side="left",
    return_tensors="pt",
).to(model.device)

outputs = model.generate(**inputs, max_new_tokens=50, do_sample=False)
print(tokenizer.batch_decode(outputs, skip_special_tokens=True))

NOTE: We need kernels from source (until we have a (minor release))

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@github-actions
Copy link
Contributor

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=44797&sha=a7358b

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

niice

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.

3 participants