Skip to content

Commit

Permalink
AOT mechanism.
Browse files Browse the repository at this point in the history
  • Loading branch information
riga committed Apr 10, 2024
1 parent 3988304 commit 33b2320
Show file tree
Hide file tree
Showing 57 changed files with 811 additions and 422 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[flake8]

# line length of 100 is recommended, but set it to a forgiving value
# line length
max-line-length = 120

# codes of errors to ignore
Expand Down
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
*.pb filter=lfs diff=lfs merge=lfs -text
*.pb.txt filter=lfs diff=lfs merge=lfs -text
*.pbtxt filter=lfs diff=lfs merge=lfs -text
*.index filter=lfs diff=lfs merge=lfs -text
*.data-* filter=lfs diff=lfs merge=lfs -text
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
*.npz
*.h5
*.hdf5
*.json
*.yaml
*.out
*.parquet
.coverage
Expand Down
37 changes: 5 additions & 32 deletions cmssw/MLProf/RuntimeMeasurement/plugins/aot/TFAOTInference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class TFAOTInference : public edm::stream::EDAnalyzer<> {
std::normal_distribution<double> normalPDFDouble_;

// aot model
tfaot::Model<tfaot_model::test_simple> model_;
// INSERT=model
};

void TFAOTInference::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
Expand Down Expand Up @@ -108,37 +108,10 @@ TFAOTInference::TFAOTInference(const edm::ParameterSet& config)
throw cms::Exception("InvalidInputType") << "input type unknown: " << inputTypeStr_;
}

// parse and register batch rules
for (size_t i = 0; i < batchRules_.size(); i++) {
std::string rule = batchRules_[i];

// extract the target batch size from the front
auto pos = rule.find(":");
if (pos == std::string::npos) {
throw cms::Exception("InvalidBatchRule") << "invalid batch rule format: " << batchRules_[i];
}
size_t batchSize = std::stoi(rule.substr(0, pos));
rule = rule.substr(pos + 1);

// loop through remaining comma-separated composite batch size
std::vector<size_t> sizes;
size_t sumSizes = 0;
while (!rule.empty()) {
pos = rule.find(",");
sizes.push_back(std::stoi(rule.substr(0, pos)));
sumSizes += sizes.back();
rule = rule.substr(pos + 1);
}

// the sum of composite batch sizes should never be smaller than the target batch size
if (sumSizes < batchSize) {
throw cms::Exception("InvalidBatchRule")
<< "sum of composite batch sizes is smaller than target batch size: " << batchRules_[i];
}

// register the batch rule
model_.setBatchRule(batchSize, sizes, sumSizes - batchSize);
std::cout << "registered batch rule for batch size " << batchSize << std::endl;
// register batch rules
for (const auto& rule : batchRules_) {
model_.setBatchRule(rule);
std::cout << "registered batch rule " << rule << std::endl;
}
}

Expand Down
78 changes: 64 additions & 14 deletions cmssw/MLProf/RuntimeMeasurement/test/onnx_runtime_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,69 @@

# setup minimal options
options = VarParsing("python")
options.setDefault("maxEvents", 1)
options.register(
"csvFile",
"results.csv",
VarParsing.multiplicity.singleton,
VarParsing.varType.string,
"path of the csv file to save results",
)
options.register(
"batchSize",
1,
VarParsing.multiplicity.singleton,
VarParsing.varType.int,
"Batch size to be tested",
"batch size to be tested",
)
options.register(
"csvFile",
"results.csv",
"inputType",
"",
VarParsing.multiplicity.singleton,
VarParsing.varType.string,
"input type; 'random', 'incremental', 'zeros', or 'ones'",
)
options.register(
"nCalls",
100,
VarParsing.multiplicity.singleton,
VarParsing.varType.int,
"number of evaluation calls for averaging",
)
options.register(
"graphPath",
"",
VarParsing.multiplicity.singleton,
VarParsing.varType.string,
"The path of the csv file to save results",
"path to the graph file",
)
options.register(
"inputTensorNames",
[],
VarParsing.multiplicity.list,
VarParsing.varType.string,
"names of the input tensors",
)
options.register(
"outputTensorNames",
[],
VarParsing.multiplicity.list,
VarParsing.varType.string,
"Names of the output tensors",
)
options.register(
"inputRanks",
[],
VarParsing.multiplicity.list,
VarParsing.varType.int,
"ranks of the input tensors",
)
options.register(
"flatInputSizes",
[],
VarParsing.multiplicity.list,
VarParsing.varType.int,
"sizes of the flattened input tensors; the amount should match the sum of ranks",
)
options.parseArguments()

Expand All @@ -29,11 +79,11 @@
process.load("FWCore.MessageService.MessageLogger_cfi")
process.MessageLogger.cerr.FwkReport.reportEvery = 1
process.maxEvents = cms.untracked.PSet(
input=cms.untracked.int32(__N_EVENTS__), # noqa
input=cms.untracked.int32(options.maxEvents),
)
process.source = cms.Source(
"PoolSource",
fileNames=cms.untracked.vstring(*__INPUT_FILES__), # noqa
fileNames=cms.untracked.vstring(options.inputFiles),
)

# process options
Expand All @@ -44,20 +94,20 @@

# multi-threading options
process.options.numberOfThreads = cms.untracked.uint32(1)
process.options.numberOfStreams = cms.untracked.uint32(0)
process.options.numberOfStreams = cms.untracked.uint32(1)
process.options.numberOfConcurrentLuminosityBlocks = cms.untracked.uint32(1)

# setup the plugin
process.load("MLProf.RuntimeMeasurement.onnxInference_cfi")
process.onnxInference.graphPath = cms.string("__GRAPH_PATH__")
process.onnxInference.inputTensorNames = cms.vstring(__INPUT_TENSOR_NAMES__) # noqa
process.onnxInference.outputTensorNames = cms.vstring(__OUTPUT_TENSOR_NAMES__) # noqa
process.onnxInference.graphPath = cms.string(options.graphPath)
process.onnxInference.inputTensorNames = cms.vstring(options.inputTensorNames)
process.onnxInference.outputTensorNames = cms.vstring(options.outputTensorNames)
process.onnxInference.outputFile = cms.string(options.csvFile)
process.onnxInference.inputType = cms.string("__INPUT_TYPE__")
process.onnxInference.inputRanks = cms.vint32(__INPUT_RANKS__) # noqa
process.onnxInference.flatInputSizes = cms.vint32(__FLAT_INPUT_SIZES__) # noqa
process.onnxInference.inputType = cms.string(options.inputType)
process.onnxInference.inputRanks = cms.vint32(options.inputRanks)
process.onnxInference.flatInputSizes = cms.vint32(options.flatInputSizes)
process.onnxInference.batchSize = cms.int32(options.batchSize)
process.onnxInference.nCalls = cms.int32(__N_CALLS__) # noqa
process.onnxInference.nCalls = cms.int32(options.nCalls)

# define what to run in the path
process.p = cms.Path(process.onnxInference)
78 changes: 64 additions & 14 deletions cmssw/MLProf/RuntimeMeasurement/test/tf_runtime_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,69 @@

# setup minimal options
options = VarParsing("python")
options.setDefault("maxEvents", 1)
options.register(
"csvFile",
"results.csv",
VarParsing.multiplicity.singleton,
VarParsing.varType.string,
"path of the csv file to save results",
)
options.register(
"batchSize",
1,
VarParsing.multiplicity.singleton,
VarParsing.varType.int,
"Batch size to be tested",
"batch size to be tested",
)
options.register(
"csvFile",
"results.csv",
"inputType",
"",
VarParsing.multiplicity.singleton,
VarParsing.varType.string,
"input type; 'random', 'incremental', 'zeros', or 'ones'",
)
options.register(
"nCalls",
100,
VarParsing.multiplicity.singleton,
VarParsing.varType.int,
"number of evaluation calls for averaging",
)
options.register(
"graphPath",
"",
VarParsing.multiplicity.singleton,
VarParsing.varType.string,
"The path of the csv file to save results",
"path to the graph file",
)
options.register(
"inputTensorNames",
[],
VarParsing.multiplicity.list,
VarParsing.varType.string,
"names of the input tensors",
)
options.register(
"outputTensorNames",
[],
VarParsing.multiplicity.list,
VarParsing.varType.string,
"Names of the output tensors",
)
options.register(
"inputRanks",
[],
VarParsing.multiplicity.list,
VarParsing.varType.int,
"ranks of the input tensors",
)
options.register(
"flatInputSizes",
[],
VarParsing.multiplicity.list,
VarParsing.varType.int,
"sizes of the flattened input tensors; the amount should match the sum of ranks",
)
options.parseArguments()

Expand All @@ -29,11 +79,11 @@
process.load("FWCore.MessageService.MessageLogger_cfi")
process.MessageLogger.cerr.FwkReport.reportEvery = 1
process.maxEvents = cms.untracked.PSet(
input=cms.untracked.int32(__N_EVENTS__), # noqa
input=cms.untracked.int32(options.maxEvents),
)
process.source = cms.Source(
"PoolSource",
fileNames=cms.untracked.vstring(*__INPUT_FILES__), # noqa
fileNames=cms.untracked.vstring(options.inputFiles),
)

# process options
Expand All @@ -44,20 +94,20 @@

# multi-threading options
process.options.numberOfThreads = cms.untracked.uint32(1)
process.options.numberOfStreams = cms.untracked.uint32(0)
process.options.numberOfStreams = cms.untracked.uint32(1)
process.options.numberOfConcurrentLuminosityBlocks = cms.untracked.uint32(1)

# setup the plugin
process.load("MLProf.RuntimeMeasurement.tfInference_cfi")
process.tfInference.graphPath = cms.string("__GRAPH_PATH__")
process.tfInference.inputTensorNames = cms.vstring(__INPUT_TENSOR_NAMES__) # noqa
process.tfInference.outputTensorNames = cms.vstring(__OUTPUT_TENSOR_NAMES__) # noqa
process.tfInference.graphPath = cms.string(options.graphPath)
process.tfInference.inputTensorNames = cms.vstring(options.inputTensorNames)
process.tfInference.outputTensorNames = cms.vstring(options.outputTensorNames)
process.tfInference.outputFile = cms.string(options.csvFile)
process.tfInference.inputType = cms.string("__INPUT_TYPE__")
process.tfInference.inputRanks = cms.vint32(__INPUT_RANKS__) # noqa
process.tfInference.flatInputSizes = cms.vint32(__FLAT_INPUT_SIZES__) # noqa
process.tfInference.inputType = cms.string(options.inputType)
process.tfInference.inputRanks = cms.vint32(options.inputRanks)
process.tfInference.flatInputSizes = cms.vint32(options.flatInputSizes)
process.tfInference.batchSize = cms.int32(options.batchSize)
process.tfInference.nCalls = cms.int32(__N_CALLS__) # noqa
process.tfInference.nCalls = cms.int32(options.nCalls)

# define what to run in the path
process.p = cms.Path(process.tfInference)
44 changes: 30 additions & 14 deletions cmssw/MLProf/RuntimeMeasurement/test/tfaot_runtime_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,42 @@

# setup minimal options
options = VarParsing("python")
options.setDefault("maxEvents", 1)
options.setDefault("maxEvents", 1)
options.register(
"csvFile",
"results.csv",
VarParsing.multiplicity.singleton,
VarParsing.varType.string,
"path of the csv file to save results",
)
options.register(
"batchSize",
1,
VarParsing.multiplicity.singleton,
VarParsing.varType.int,
"Batch size to be tested",
"batch size to be tested",
)
options.register(
"batchRules",
[],
VarParsing.multiplicity.list,
"inputType",
"",
VarParsing.multiplicity.singleton,
VarParsing.varType.string,
"Batch rules (format 'target_size:size_1,size_2,...') to be configured",
"input type; 'random', 'incremental', 'zeros', or 'ones'",
)
options.register(
"csvFile",
"results.csv",
"nCalls",
100,
VarParsing.multiplicity.singleton,
VarParsing.varType.int,
"number of evaluation calls for averaging",
)
options.register(
"batchRules",
[],
VarParsing.multiplicity.list,
VarParsing.varType.string,
"The path of the csv file to save results",
"Batch rules (format 'target_size:size_1:size_2:...') to be configured",
)
options.parseArguments()

Expand All @@ -36,11 +52,11 @@
process.load("FWCore.MessageService.MessageLogger_cfi")
process.MessageLogger.cerr.FwkReport.reportEvery = 1
process.maxEvents = cms.untracked.PSet(
input=cms.untracked.int32(__N_EVENTS__), # noqa
input=cms.untracked.int32(options.maxEvents),
)
process.source = cms.Source(
"PoolSource",
fileNames=cms.untracked.vstring(*__INPUT_FILES__), # noqa
fileNames=cms.untracked.vstring(options.inputFiles),
)

# process options
Expand All @@ -51,16 +67,16 @@

# multi-threading options
process.options.numberOfThreads = cms.untracked.uint32(1)
process.options.numberOfStreams = cms.untracked.uint32(0)
process.options.numberOfStreams = cms.untracked.uint32(1)
process.options.numberOfConcurrentLuminosityBlocks = cms.untracked.uint32(1)

# setup the plugin
process.load("MLProf.RuntimeMeasurement.tfaotInference_cfi")
process.tfaotInference.outputFile = cms.string(options.csvFile)
process.tfaotInference.inputType = cms.string("__INPUT_TYPE__")
process.tfaotInference.batchRules = cms.vstring(options.batchRules)
process.tfaotInference.inputType = cms.string(options.inputType)
process.tfaotInference.batchRules = cms.vstring([r.replace(".", ",") for r in options.batchRules])
process.tfaotInference.batchSize = cms.int32(options.batchSize)
process.tfaotInference.nCalls = cms.int32(__N_CALLS__) # noqa
process.tfaotInference.nCalls = cms.int32(options.nCalls)

# define what to run in the path
process.p = cms.Path(process.tfaotInference)
Loading

0 comments on commit 33b2320

Please sign in to comment.