Skip to content

MatMulNBits: report not stateless to skip eager const-eval#2445

Open
Reza2kn wants to merge 1 commit into
sonos:mainfrom
Reza2kn:matmulnbits-stateless-fix
Open

MatMulNBits: report not stateless to skip eager const-eval#2445
Reza2kn wants to merge 1 commit into
sonos:mainfrom
Reza2kn:matmulnbits-stateless-fix

Conversation

@Reza2kn

@Reza2kn Reza2kn commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Type inference eager-const-evaluates a constant-input MatMulNBits by rebuilding and optimizing each op in isolation to fold it, which is far slower than deferring the fold to into_optimized and can dominate load time on int4 models with many quantized matmuls. Reporting the op as not stateless skips that eager path; the constant fold still happens in into_optimized.

🍍

Type inference eager-const-evaluates a stateless op whose inputs are all constant, and for MatMulNBits that folds it by rebuilding and optimizing the op in isolation, far more costly than the fold into_optimized already does over the whole graph. Report the op as not stateless so the eager path is skipped; the constant fold still happens in into_optimized.
@kali

kali commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Hey ! thanks for your interest in tract !

Good eye, right diagnostic, but I think we have a better fix. I plead guilty on having abused the stateless flag myself, so it's very understandable.

I think the right fix is in hir/src/infer/ops.rs, around the line 30, mimicking core/src/model/typed.rs:89, and if it works, it should fix in one place this class of bug. Care to give it a shot ?

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