Skip to content

Have a way to load inputs from a file in stablehlo-translate #2912

@pstarkcdpr

Description

@pstarkcdpr

Request description

I was comparing the output and stablehlo-translate and iree-run-module to track down a bug in IREE, but I had trouble passing in arguments to stablehlo-translate. The method seems to be

stablehlo-translate model.mlir --interpret --args=[dense<...>: tensor<...>]

While it would be nice to be able to pass in npy files (probe outputs are npy so this doesn't seem out of scope), I'm fine with converting npy to dense. The problem happens with a large model where passing in the parameters is just too big for the command-line to handle.

My suggestion is to copy what IREE does and allow files to be passed in if they are prefixed with @. For example

stablehlo-translate model.mlir --interpret --args=@inputs.mlir

I needed to do this locally for the sake of my testing, but I wasn't sure if this is something that StableHLO would be interested in doing in general. If not, then feel to close this issue.

What I did locally was to quickly just shove in support for reading from file, which was just a few lines of code in parseInterpreterArguments in StablehloTranslateMain.cpp:

   if (!argsStr.empty()) {
    if (argsStr[0] == '@') {
      std::ifstream tmp_stream(argsStr.substr(1));
      if (!tmp_stream.is_open()) {
        return parseError("failed to input argument file");
      }
      argsStr = std::string((std::istreambuf_iterator<char>(tmp_stream)),
                                        std::istreambuf_iterator<char>());
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions