Skip to content

Linalg/XeGPU llama3 forward-pass example - #235

Open
nbpatel wants to merge 6 commits into
llvm:mainfrom
nbpatel:llama
Open

nbpatel wants to merge 6 commits into
llvm:mainfrom
nbpatel:llama

Conversation

@nbpatel

@nbpatel nbpatel commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

This PR adds a Llama-3 model script under examples/xegpu, a full Llama-3-style transformer forward pass (6 layers, C=256, H=4 query heads / n_kv=2 KV heads, head_size=64, hidden=1024, T=256) running end-to-end on the Intel GPU via the XeGPU lowering path.

Assisted by Claude

@charithaintc charithaintc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall looks good. I will wait for other reviews.

Comment thread examples/xegpu/llama3.py Outdated
@nbpatel
nbpatel marked this pull request as ready for review July 28, 2026 02:17

@tkarna tkarna left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good overall, minor comments. The lowering schedule seems quite hard-coded/brittle but we can improve it later on.

Comment thread examples/xegpu/llama3_payload.py Outdated
Comment thread examples/xegpu/llama3_payload.py Outdated
Comment thread examples/xegpu/llama3_schedule.py Outdated
Comment thread examples/xegpu/llama3_schedule.py Outdated
Comment thread examples/xegpu/llama3_schedule.py Outdated
Comment thread examples/xegpu/llama3_schedule.py Outdated
Comment thread examples/xegpu/llama3_schedule.py Outdated
Comment thread examples/xegpu/llama3_schedule.py Outdated
ln_params["T"],
)

# 2) Tile ew generics into own foralls (handles preserved across rms tiling).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AFAIU this creates standalone gpu kernels for the elementwise ops. Could they be fused into their producer or consumer matmuls instead?

Comment thread examples/xegpu/llama3.py Outdated
Comment thread examples/xegpu/llama3.py Outdated
Comment on lines +295 to +303
an=np.ones(C, np.float32),
wq=(np.random.randn(C, C) * sc).astype(np.float16),
wk=(np.random.randn(C, kv_dim) * sc).astype(np.float16),
wv=(np.random.randn(C, kv_dim) * sc).astype(np.float16),
wo=(np.random.randn(C, C) * sc).astype(np.float16),
fn=np.ones(C, np.float32),
w1=(np.random.randn(C, hidden) * sc).astype(np.float16),
w2=(np.random.randn(hidden, C) * sc).astype(np.float16),
w3=(np.random.randn(C, hidden) * sc).astype(np.float16),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: maybe these dict keys could also be made more human readable?

@tkarna tkarna mentioned this pull request Aug 10, 2026

@tkarna tkarna left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me.

It seems the correctness test is not passing anymore with the latest mlir version. Let's wait for a fix upstream before merging.

@nbpatel

nbpatel commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Looks good to me.

It seems the correctness test is not passing anymore with the latest mlir version. Let's wait for a fix upstream before merging.

llvm/llvm-project#224459 fixes this

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.

4 participants