Support loading interpreter arguments from a file in stablehlo-translate - #2979
Open
hamzaqureshi5 wants to merge 5 commits into
Open
Support loading interpreter arguments from a file in stablehlo-translate#2979hamzaqureshi5 wants to merge 5 commits into
hamzaqureshi5 wants to merge 5 commits into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Author
|
@GleasonK PR is ready for review |
abhigunj
self-requested a review
August 5, 2026 21:36
abhigunj
reviewed
Aug 9, 2026
abhigunj
approved these changes
Aug 17, 2026
Inline --args puts entire input tensors on the command line, which exceeds OS argument-length limits for realistically sized models. Allow --args=@file, where the file contains the same array attribute text as the inline form. Fixes openxla#2912 (IREE-style @ prefix; .npy input support to follow).
Extend --args=@file to accept comma-separated .npy files, each providing one input tensor with its type inferred from the NumPy header. This closes the loop with interpreter.probe, whose serialized outputs can now be fed back in as interpreter inputs. Type inference covers little-endian integer and f32/f64 dtypes. Types without a native NumPy representation (bool, f16, bf16, complex) are serialized under substitute descrs and cannot be unambiguously inferred, so they are rejected with a clear error. Also fixes latent bugs in the NumPy reader that inference exposed (previously unreachable because the parsed shape was never used): - parseShapeHeader returned a dangling ArrayRef and prepended four zero dims; it now returns an owned, correctly-bounded vector, and the file's shape is validated against the expected type. - Header sizes above 127 bytes were sign-extended into negative values. - i64/ui64 type dispatch was inverted relative to every other width, so signless i64 tensors serialized with a 'u8' descr and vice versa. Together with the previous commit, completes openxla#2912.
- Validate the .npy extension across all comma-separated args files instead of only the last one, so `--args=@a.npy,b.txt` reports "cannot mix .npy and non-.npy args files" rather than silently treating the whole string as a single file name. Multiple files remain supported only for .npy args. - Restore api_input_arguments.mlir to its original contents and move the @file tests to a new api_input_arguments_from_file.mlir. File related errors now use their own usage hint, leaving the existing attribute parsing messages unchanged.
abhigunj
force-pushed
the
interpreter-args-file
branch
from
August 17, 2026 22:16
c54d7c8 to
8545947
Compare
Member
|
LGTM, lint check is failing, fix that. ready to merge. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2912.
--argscurrently requires spelling out every input tensor inline, whichexceeds OS argument-length limits for realistically sized models. This PR
adds an IREE-style
@prefix for reading arguments from files, in twocommits:
1.
--args=@fileThe file contains the same array-attribute text as the inline form:
2.
--args=@a.npy,@b.npyComma-separated NumPy files, each providing one input tensor. The tensor
type is inferred from the file's header, so probe outputs
(
--probe-output-dir) can be fed back in as interpreter inputs directly:Type inference covers little-endian integer and f32/f64 dtypes. Types
without a native NumPy representation (bool, f16, bf16, complex) are
serialized by
serializeTensorunder substitute descrs, so they can't beunambiguously inferred and are rejected with a clear error. Extending
these is left for a follow-up.
NumPy reader fixes
Wiring up inference exposed three latent bugs in
NumPy.cpp, previouslyunreachable because the parsed shape was never used. Note the last one
changes the
descrthat probe files are written with:parseShapeHeaderreturned anArrayRefto a local vector andpre-filled four zero dims; it now returns an owned, correctly-bounded
vector, and the file's shape is validated against the expected type.
so signless i64 tensors serialized with a
'u8'descr and vice versa.Write and read stay consistent with each other, as before.
Testing
stablehlo/tests/interpret/api_input_arguments.mlir:@filepositiveand missing-file cases.
stablehlo/tests/interpret/api_input_arguments_npy.mlir: writes thearguments to
.npyviainterpreter.probe, then loads them back as--argsinputs (round-trips the serializer/reader pair); plusmissing-file and mixed-file error cases.
'|i1'int8,'<i8'int64, and bool → rejected as unsupported).ninja check-stablehlo-testspasses.