Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[e2e] add profiler entry for single stablehlo/mhlo file #357

Merged
merged 4 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ def inner_compile(gm: torch.fx.GraphModule,
module = torch_frontend.compile_dynamo_model(
gm,
output_type="stablehlo",
backend_legal_ops=BACKEND_LEGAL_OPS,
debug=DebugType.PRINT_AFTER_FALIURE)
backend_legal_ops=BACKEND_LEGAL_OPS)
with open(stablehlo_file, "w") as f:
print(module.operation.get_asm(), file=f)
if not os.path.exists(byre_file):
Expand Down
23 changes: 11 additions & 12 deletions tests/numerical_test/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def profile(self, inputs, outputs, warmup_trials=10, run_trials=50):
return ((end - start) * 1000) / run_trials


def compile_and_run_mlir(mhlo_file, target, verbose, mode="numerical", **kwargs):
def compile_and_run_mlir(mhlo_file, target, verbose, mode="numerical", workdir="./local_test", unique_name=None, **kwargs):
try:
data_generator = MLIRDataGenerator(mhlo_file, target)
entry_func_name = data_generator.entry_func_name
Expand All @@ -236,12 +236,12 @@ def compile_and_run_mlir(mhlo_file, target, verbose, mode="numerical", **kwargs)
interp = Interpreter.load_from_file(mhlo_file, is_stablehlo=True)
golden_outputs = interp.call_function(entry_func_name, np_inputs)

unique_name = os.path.basename(mhlo_file).split(".")[0] + "." + target
if unique_name is None:
unique_name = os.path.basename(mhlo_file).split(".")[0] + "." + target
# byteir compile
TEMP_FOLDER = "./local_test"
os.makedirs(TEMP_FOLDER, exist_ok=True)
os.makedirs(TEMP_FOLDER + f"/{unique_name}", exist_ok=True)
output_mlir_file_name = f"{TEMP_FOLDER}/{unique_name}/{unique_name}.rt.mlir"
os.makedirs(workdir, exist_ok=True)
os.makedirs(workdir + f"/{unique_name}", exist_ok=True)
output_mlir_file_name = f"{workdir}/{unique_name}/{unique_name}.rt.mlir"
byteir.compile(
mhlo_file,
output_mlir_file_name,
Expand Down Expand Up @@ -317,7 +317,7 @@ def compile_and_run_mlir(mhlo_file, target, verbose, mode="numerical", **kwargs)
)


def compile_and_run_torch(test, target, verbose, mode="numerical"):
def compile_and_run_torch(test, target, verbose, mode="numerical", workdir="./local_test"):
import torch_frontend

cur_device = get_target_device(target)
Expand All @@ -339,11 +339,10 @@ def compile_and_run_torch(test, target, verbose, mode="numerical"):

unique_name = test.unique_name + "." + target
# byteir compile
TEMP_FOLDER = "./local_test"
os.makedirs(TEMP_FOLDER, exist_ok=True)
os.makedirs(TEMP_FOLDER + f"/{unique_name}", exist_ok=True)
mlir_file_name = f"{TEMP_FOLDER}/{unique_name}/{unique_name}.stablehlo.mlir"
output_mlir_file_name = f"{TEMP_FOLDER}/{unique_name}/{unique_name}.rt.mlir"
os.makedirs(workdir, exist_ok=True)
os.makedirs(workdir + f"/{unique_name}", exist_ok=True)
mlir_file_name = f"{workdir}/{unique_name}/{unique_name}.stablehlo.mlir"
output_mlir_file_name = f"{workdir}/{unique_name}/{unique_name}.rt.mlir"
with open(mlir_file_name, "w+") as fout:
compiled_graph.operation.print(file=fout, large_elements_limit=None)
byteir.compile(
Expand Down
34 changes: 34 additions & 0 deletions tests/numerical_test/profiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2022 ByteDance Ltd. and/or its affiliates. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

import argparse

from execute import compile_and_run_mlir
from reporting import report_results

def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("input_mlir_path")
parser.add_argument("--workdir", type=str, default="./profiling", help="workspace directory")
parser.add_argument("--name", type=str, default="model")
parser.add_argument("--target", type=str, default="cuda", choices=["cpu", "cuda", "cuda_with_ait"])
parser.add_argument("--mode", type=str, default="profile", choices=["numerical", "profile"])
parser.add_argument("-v", "--verbose", default=False, action="store_true")
return parser.parse_args()

if __name__ == "__main__":
args = parse_args()

result = compile_and_run_mlir(args.input_mlir_path, args.target, args.verbose, mode=args.mode, workdir=args.workdir, unique_name=args.name)
report_results([result])
Loading