Skip to content

cse: skip merging >64MB single-output ops - #5257

Open
rlegithub wants to merge 1 commit into
ROCm:developfrom
rlegithub:pr/cse-skip-large-single-output
Open

rlegithub wants to merge 1 commit into
ROCm:developfrom
rlegithub:pr/cse-skip-large-single-output

Conversation

@rlegithub

Copy link
Copy Markdown

Summary

Common-subexpression elimination that merges very large (>64 MB) single-output ops can drive excessive peak memory on deep quantized LLMs (observed OOM on int4 models). This guards CSE to skip merging such large single-output ops.

Test plan

  • CI
  • Verified on gfx1151: deep int4 LLM no longer OOMs during compile.

eliminate_common_subexpression merged the structurally-identical per-layer INT4
weight-dequant tiles (~531MB each) across all layers, making their outputs share
one producer and stay co-live -> memory_coloring scratch scaled O(num_layers)
(~0.86GB/layer) -> GPU OOM on deep models (52-layer Onyx/Llama-4). Add a 64MB
single-output size guard so CSE still de-dups small common ops (needed by the
embedding-gather path) but leaves large weight-dequants independent and reusable.

Full 52-layer Onyx INT4 now compiles + runs on gfx1151 (was OOM): 67GB mxr
cached, exit 0, 5.4 tok/s. (Output correctness at full depth tracked separately.)

Co-Authored-By: Claude <noreply@anthropic.com>
(cherry picked from commit 97ae9c1a3329ed67d76cb6c83caccda236925e1e)
@pfultz2

pfultz2 commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator

I dont think we should do this here. If this is caused by long liveness then we could analyze that in another pass and then duplicate calculation before scheduling and memory coloring.

@rlegithub
rlegithub marked this pull request as ready for review September 14, 2026 19:26
@rlegithub
rlegithub requested a review from causten as a code owner September 14, 2026 19:26
if(not s.sub_shapes().empty())
return false;
return s.bytes() > threshold;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This can massively increase memory usage and calculations especially since this targets large outputs.

This should be done as another pass to check the liveness benefit against the cost of recalculating.

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