Skip to content

Commit

Permalink
Add options to specify directory with ONNX initializer files
Browse files Browse the repository at this point in the history
  • Loading branch information
ljfitz committed Feb 11, 2025
1 parent f4d1ac4 commit 17fb894
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/Compiler/CompilerOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ int repeatOnnxTransform; // onnx-mlir only
std::string shapeInformation; // onnx-mlir only
std::string dimParams; // onnx-mlir only
ModelSize modelSize; // onnx-mlir only
std::string externalDataDir; // onnx-mlir only
bool storeConstantsToFile; // onnx-mlir only
float constantsToFileTotalThreshold; // onnx-mlir only
float constantsToFileSingleThreshold; // onnx-mlir only
Expand Down Expand Up @@ -392,6 +393,16 @@ static llvm::cl::opt<ModelSize, true> modelSizeOpt("modelSize",
llvm::cl::init(small), llvm::cl::cat(OnnxMlirOptions),
llvm::cl::ValueRequired);

static llvm::cl::opt<std::string, true> externalDataDirOpt("external-data-dir",
llvm::cl::desc(
"ONNX constant initializers can be stored in a separate file. "
"The filename is stored in the ONNX model without a path. By default "
"the path is the same folder as the ONNX model. This allows that "
"default to be overridden.\n"
"Default is empty (use default)."),
llvm::cl::location(externalDataDir), llvm::cl::init(""),
llvm::cl::cat(OnnxMlirOptions));

static llvm::cl::opt<bool, true> storeConstantsToFileOpt(
"store-constants-to-file",
llvm::cl::desc(
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/CompilerOptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ extern int repeatOnnxTransform; // onnx-mlir only
extern std::string shapeInformation; // onnx-mlir only
extern std::string dimParams; // onnx-mlir only
extern ModelSize modelSize; // onnx-mlir only
extern std::string externalDataDir; // onnx-mlir only
extern bool storeConstantsToFile; // onnx-mlir only
extern float constantsToFileTotalThreshold; // onnx-mlir only
extern float constantsToFileSingleThreshold; // onnx-mlir only
Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/CompilerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,8 @@ int processInputFile(StringRef inputFilename, mlir::MLIRContext &context,
options.shapeInformation = shapeInformation;
options.dimParams = dimParams;
options.allowSorting = allowSorting;
options.externalDataDir = dirName(inputFilename);
options.externalDataDir =
externalDataDir.empty() ? dirName(inputFilename) : externalDataDir;
options.functionsToDecompose.insert(options.functionsToDecompose.end(),
functionsToDecompose.begin(), functionsToDecompose.end());
return ImportFrontendModelFile(
Expand Down

0 comments on commit 17fb894

Please sign in to comment.