diff --git a/_doc/examples/plot_dump_intermediate_results.py b/_doc/examples/plot_dump_intermediate_results.py index 6ce8f8fb..adbfa841 100644 --- a/_doc/examples/plot_dump_intermediate_results.py +++ b/_doc/examples/plot_dump_intermediate_results.py @@ -32,7 +32,6 @@ from onnx_diagnostic.helpers.mini_onnx_builder import create_input_tensors_from_onnx_model from onnx_diagnostic.reference import OnnxruntimeEvaluator, ReportResultComparison - model, inputs, ds = dummy_llm(dynamic_shapes=True) # %% diff --git a/_doc/examples/plot_export_tiny_llm.py b/_doc/examples/plot_export_tiny_llm.py index 64b24085..2376a65a 100644 --- a/_doc/examples/plot_export_tiny_llm.py +++ b/_doc/examples/plot_export_tiny_llm.py @@ -35,7 +35,6 @@ from onnx_diagnostic.torch_models.llms import get_tiny_llm from onnx_diagnostic.torch_export_patches.patch_inputs import use_dyn_not_str - MODEL_NAME = "arnir0/Tiny-LLM" tokenizer = transformers.AutoTokenizer.from_pretrained(MODEL_NAME) model = transformers.AutoModelForCausalLM.from_pretrained(MODEL_NAME) diff --git a/_doc/examples/plot_export_tiny_llm_dim01.py b/_doc/examples/plot_export_tiny_llm_dim01.py index 6676318a..f47395fe 100644 --- a/_doc/examples/plot_export_tiny_llm_dim01.py +++ b/_doc/examples/plot_export_tiny_llm_dim01.py @@ -30,7 +30,6 @@ register_additional_serialization_functions, ) - data = get_untrained_model_with_inputs("arnir0/Tiny-LLM", add_second_input=True) model, dynamic_shapes = data["model"], data["dynamic_shapes"] diff --git a/_doc/examples/plot_export_tiny_llm_dim01_onnx.py b/_doc/examples/plot_export_tiny_llm_dim01_onnx.py index 2855e722..2f869c5f 100644 --- a/_doc/examples/plot_export_tiny_llm_dim01_onnx.py +++ b/_doc/examples/plot_export_tiny_llm_dim01_onnx.py @@ -30,7 +30,6 @@ register_additional_serialization_functions, ) - data = get_untrained_model_with_inputs("arnir0/Tiny-LLM", add_second_input=True) model, dynamic_shapes = data["model"], data["dynamic_shapes"] diff --git a/_doc/examples/plot_export_tiny_llm_dim01_onnx_custom.py b/_doc/examples/plot_export_tiny_llm_dim01_onnx_custom.py index ec4bc09f..1c1510fd 100644 --- a/_doc/examples/plot_export_tiny_llm_dim01_onnx_custom.py +++ b/_doc/examples/plot_export_tiny_llm_dim01_onnx_custom.py @@ -29,7 +29,6 @@ ) from experimental_experiment.torch_interpreter import to_onnx, ExportOptions - data = get_untrained_model_with_inputs("arnir0/Tiny-LLM", add_second_input=True) model, dynamic_shapes = data["model"], data["dynamic_shapes"] diff --git a/_doc/examples/plot_export_tiny_llm_method_generate.py b/_doc/examples/plot_export_tiny_llm_method_generate.py index 7a2c80e9..6859ebe1 100644 --- a/_doc/examples/plot_export_tiny_llm_method_generate.py +++ b/_doc/examples/plot_export_tiny_llm_method_generate.py @@ -22,7 +22,6 @@ from onnx_diagnostic import doc from onnx_diagnostic.export.api import method_to_onnx - MODEL_NAME = "arnir0/Tiny-LLM" tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME) model = AutoModelForCausalLM.from_pretrained(MODEL_NAME) diff --git a/_doc/examples/plot_export_tiny_llm_patched.py b/_doc/examples/plot_export_tiny_llm_patched.py index 387b781b..760787d1 100644 --- a/_doc/examples/plot_export_tiny_llm_patched.py +++ b/_doc/examples/plot_export_tiny_llm_patched.py @@ -73,7 +73,6 @@ from onnx_diagnostic.torch_export_patches.patch_inputs import use_dyn_not_str from onnx_diagnostic.torch_models.llms import get_tiny_llm - experiment = get_tiny_llm() untrained_model, inputs, dynamic_shapes = ( experiment["model"], diff --git a/_doc/recipes/plot_export_cond.py b/_doc/recipes/plot_export_cond.py index 68be9138..46668d98 100644 --- a/_doc/recipes/plot_export_cond.py +++ b/_doc/recipes/plot_export_cond.py @@ -16,7 +16,6 @@ from onnx_diagnostic import doc from onnx_diagnostic.torch_export_patches import torch_export_rewrite - # %% # We define a model with a control flow (-> graph break) diff --git a/_doc/technical/plot_generate.py b/_doc/technical/plot_generate.py index 72e9675f..679d9644 100644 --- a/_doc/technical/plot_generate.py +++ b/_doc/technical/plot_generate.py @@ -32,7 +32,6 @@ from onnx_diagnostic.tasks import random_input_kwargs from onnx_diagnostic.export.api import to_onnx - device = "cuda" if torch.cuda.is_available() else "cpu" data = [] diff --git a/_unittests/ut_helpers/test_dot_helper.py b/_unittests/ut_helpers/test_dot_helper.py index 3c885149..a2b52d97 100644 --- a/_unittests/ut_helpers/test_dot_helper.py +++ b/_unittests/ut_helpers/test_dot_helper.py @@ -38,8 +38,7 @@ def test_custom_doc_kernels_layer_normalization(self): opset_imports=[oh.make_opsetid("", 18)], ) dot = to_dot(model) - expected = textwrap.dedent( - """ + expected = textwrap.dedent(""" digraph { graph [rankdir=TB, splines=true, overlap=false, nodesep=0.2, ranksep=0.2, fontsize=8]; node [style="rounded,filled", color="#888888", fontcolor="#222222", shape=box]; @@ -57,8 +56,7 @@ def test_custom_doc_kernels_layer_normalization(self): O_5 [label="Z\\nFLOAT16(b,c,d)", fillcolor="#aaaaee"]; Add_4 -> O_5; } - """ - ) + """) self.maxDiff = None self.assertEqual(expected.strip("\n "), dot.strip("\n ")) @@ -90,9 +88,7 @@ def test_custom_doc_kernels_layer_normalization_constant(self): opset_imports=[oh.make_opsetid("", 18)], ) dot = to_dot(model) - expected = ( - textwrap.dedent( - """ + expected = textwrap.dedent(""" digraph { graph [rankdir=TB, splines=true, overlap=false, nodesep=0.2, ranksep=0.2, fontsize=8]; node [style="rounded,filled", color="#888888", fontcolor="#222222", shape=box]; @@ -111,11 +107,7 @@ def test_custom_doc_kernels_layer_normalization_constant(self): O_6 [label="Z\\nFLOAT16(b,c,d)", fillcolor="#aaaaee"]; Add_5 -> O_6; } - """ - ) - .strip("\n") - .replace(" ", "") - ) + """).strip("\n").replace(" ", "") self.maxDiff = None self.assertEqual(expected, dot.strip("\n").replace(" ", "")) diff --git a/_unittests/ut_helpers/test_helper.py b/_unittests/ut_helpers/test_helper.py index 1aef9297..6b407cc9 100644 --- a/_unittests/ut_helpers/test_helper.py +++ b/_unittests/ut_helpers/test_helper.py @@ -51,7 +51,6 @@ ) from onnx_diagnostic.torch_models.hghub.hub_api import get_pretrained_config - TFLOAT = onnx.TensorProto.FLOAT diff --git a/_unittests/ut_helpers/test_log_helper.py b/_unittests/ut_helpers/test_log_helper.py index df8af469..2465862f 100644 --- a/_unittests/ut_helpers/test_log_helper.py +++ b/_unittests/ut_helpers/test_log_helper.py @@ -24,19 +24,13 @@ class TestLogHelper(ExtTestCase): @classmethod def df1(cls): - return pandas.read_csv( - io.StringIO( - textwrap.dedent( - """ + return pandas.read_csv(io.StringIO(textwrap.dedent(""" date,version_python,version_transformers,model_name,model_exporter,time_load,time_latency,time_baseline,disc_ort,disc_ort2 2025/01/01,3.13.3,4.52.4,phi3,export,0.51,0.1,0.1,1e-5,1e-5 2025/01/02,3.13.3,4.52.4,phi3,export,0.62,0.11,0.11,1e-5,1e-5 2025/01/01,3.13.3,4.52.4,phi4,export,0.53,0.1,0.105,1e-5,1e-5 2025/01/01,3.12.3,4.52.4,phi4,onnx-dynamo,0.54,0.14,0.999,1e-5,1e-5 - """ - ) - ) - ) + """))) @classmethod def cube1(cls, verbose=0): diff --git a/_unittests/ut_helpers/test_onnx_helper.py b/_unittests/ut_helpers/test_onnx_helper.py index b925e24c..1ba5c9fd 100644 --- a/_unittests/ut_helpers/test_onnx_helper.py +++ b/_unittests/ut_helpers/test_onnx_helper.py @@ -33,7 +33,6 @@ _enumerate_model_node_outputs, ) - TFLOAT = TensorProto.FLOAT TINT64 = TensorProto.INT64 diff --git a/_unittests/ut_reference/test_torch_onnx_evaluator.py b/_unittests/ut_reference/test_torch_onnx_evaluator.py index ce3d0fcd..8254e54a 100644 --- a/_unittests/ut_reference/test_torch_onnx_evaluator.py +++ b/_unittests/ut_reference/test_torch_onnx_evaluator.py @@ -16,7 +16,6 @@ from onnx_diagnostic.reference.torch_ops import OpRunKernel, OpRunTensor from onnx_diagnostic.reference.torch_evaluator import get_kernels - TFLOAT = onnx.TensorProto.FLOAT TFLOAT16 = onnx.TensorProto.FLOAT16 TINT64 = onnx.TensorProto.INT64 diff --git a/_unittests/ut_torch_export_patches/test_patch_module.py b/_unittests/ut_torch_export_patches/test_patch_module.py index 4f822f2c..e38d6678 100644 --- a/_unittests/ut_torch_export_patches/test_patch_module.py +++ b/_unittests/ut_torch_export_patches/test_patch_module.py @@ -508,12 +508,10 @@ def test_shape_finder(self): self.assertEqual({"x"}, sh.found_shape) def test__find_loop_vars(self): - code = textwrap.dedent( - """ + code = textwrap.dedent(""" for i in range(x.shape[0]): z[i, :] = ((x[i : i + 1, :] - y) ** 2).sum(dim=-1) - """ - ) + """) node = ast.parse(code) tr = RewriteControlFlow() vars = tr._find_loop_vars(node.body[0]) diff --git a/_unittests/ut_xrun_doc/test_documentation_examples.py b/_unittests/ut_xrun_doc/test_documentation_examples.py index 556e6297..39b8b2ff 100644 --- a/_unittests/ut_xrun_doc/test_documentation_examples.py +++ b/_unittests/ut_xrun_doc/test_documentation_examples.py @@ -14,7 +14,6 @@ ignore_errors, ) - VERBOSE = 0 ROOT = os.path.realpath(os.path.abspath(os.path.join(onnx_diagnostic_file, "..", ".."))) diff --git a/_unittests/ut_xrun_doc/test_documentation_recipes.py b/_unittests/ut_xrun_doc/test_documentation_recipes.py index b821a457..a6dcf9fe 100644 --- a/_unittests/ut_xrun_doc/test_documentation_recipes.py +++ b/_unittests/ut_xrun_doc/test_documentation_recipes.py @@ -12,7 +12,6 @@ ignore_errors, ) - VERBOSE = 0 ROOT = os.path.realpath(os.path.abspath(os.path.join(onnx_diagnostic_file, "..", ".."))) diff --git a/_unittests/ut_xrun_doc/test_documentation_technical.py b/_unittests/ut_xrun_doc/test_documentation_technical.py index c674ef0c..31eb4394 100644 --- a/_unittests/ut_xrun_doc/test_documentation_technical.py +++ b/_unittests/ut_xrun_doc/test_documentation_technical.py @@ -13,7 +13,6 @@ has_transformers, ) - VERBOSE = 0 ROOT = os.path.realpath(os.path.abspath(os.path.join(onnx_diagnostic_file, "..", ".."))) diff --git a/onnx_diagnostic/_command_lines_parser.py b/onnx_diagnostic/_command_lines_parser.py index 9aa7db7c..7177ddb9 100644 --- a/onnx_diagnostic/_command_lines_parser.py +++ b/onnx_diagnostic/_command_lines_parser.py @@ -14,11 +14,9 @@ def get_parser_dot() -> ArgumentParser: parser = ArgumentParser( prog="dot", - description=textwrap.dedent( - """ + description=textwrap.dedent(""" Converts a model into a dot file dot can draw into a graph. - """ - ), + """), ) parser.add_argument("input", type=str, help="onnx model to lighten") parser.add_argument( @@ -85,12 +83,10 @@ def _cmd_dot(argv: List[Any]): def get_parser_lighten() -> ArgumentParser: parser = ArgumentParser( prog="lighten", - description=textwrap.dedent( - """ + description=textwrap.dedent(""" Removes the weights from a heavy model, stores statistics to restore random weights. - """ - ), + """), epilog="This is mostly used to write unit tests without adding " "a big onnx file to the repository.", ) @@ -142,12 +138,10 @@ def _cmd_lighten(argv: List[Any]): def get_parser_unlighten() -> ArgumentParser: parser = ArgumentParser( prog="unlighten", - description=textwrap.dedent( - """ + description=textwrap.dedent(""" Restores random weights for a model reduces with command lighten, the command expects to find a file nearby with extension '.stats'. - """ - ), + """), epilog="This is mostly used to write unit tests without adding " "a big onnx file to the repository.", ) @@ -200,8 +194,7 @@ def get_parser_print() -> ArgumentParser: "fmt", choices=["dot", "pretty", "printer", "raw", "shape", "text"], default="pretty", - help=textwrap.dedent( - """ + help=textwrap.dedent(""" Prints out a model on the standard output. dot - converts the graph into dot @@ -211,10 +204,7 @@ def get_parser_print() -> ArgumentParser: shape - prints every node node with input and output shapes text - uses GraphRendering - """.strip( - "\n" - ) - ), + """.strip("\n")), ) parser.add_argument("input", type=str, help="onnx model to load") return parser @@ -251,12 +241,10 @@ def _cmd_print(argv: List[Any]): def get_parser_find() -> ArgumentParser: parser = ArgumentParser( prog="find", - description=textwrap.dedent( - """ + description=textwrap.dedent(""" Look into a model and search for a set of names, tells which node is consuming or producing it. - """ - ), + """), epilog="Enables Some quick validation.", ) parser.add_argument( @@ -315,12 +303,10 @@ def _cmd_find(argv: List[Any]): def get_parser_config() -> ArgumentParser: parser = ArgumentParser( prog="config", - description=textwrap.dedent( - """ + description=textwrap.dedent(""" Prints out a configuration for a model id, prints the associated task as well. - """ - ), + """), formatter_class=RawTextHelpFormatter, epilog="", ) @@ -470,8 +456,7 @@ def get_parser_validate(name: str = "validate") -> ArgumentParser: Creates a script to export a model for a particular task given the model id. """ ), - epilog=textwrap.dedent( - f""" + epilog=textwrap.dedent(f""" If the model id is specified, one untrained version of it is instantiated. Examples: @@ -500,8 +485,7 @@ def get_parser_validate(name: str = "validate") -> ArgumentParser: pyinstrument -m onnx_diagnostic {name} ... pyinstrument -r html -o profile.html -m onnx_diagnostic {name} ... - """ - ), + """), formatter_class=RawTextHelpFormatter, ) parser.add_argument("-m", "--mid", type=str, help="model id, usually /") @@ -527,17 +511,13 @@ def get_parser_validate(name: str = "validate") -> ArgumentParser: default=True, action=_BoolOrParseDictPatch, nargs="*", - help=textwrap.dedent( - """ + help=textwrap.dedent(""" Applies patches before exporting, it can be a boolean to enable to disable the patches or be more finetuned (default is True). It is possible to disable patch for torch by adding: --patch "patch_sympy=False" --patch "patch_torch=False" - """.strip( - "\n" - ) - ), + """.strip("\n")), ) parser.add_argument( "--rewrite", @@ -567,16 +547,12 @@ def get_parser_validate(name: str = "validate") -> ArgumentParser: "--inputs2", default=1, type=int, - help=textwrap.dedent( - """ + help=textwrap.dedent(""" Validates or exports the model on a second set of inputs to check the exported model supports dynamism. The values is used as an increment to the first set of inputs. A high value may trick a different behavior in the model and missed by the exporter. - """.strip( - "\n" - ) - ), + """.strip("\n")), ) parser.add_argument( "--runtime", @@ -609,15 +585,11 @@ def get_parser_validate(name: str = "validate") -> ArgumentParser: parser.add_argument( "--ortfusiontype", required=False, - help=textwrap.dedent( - """ + help=textwrap.dedent(""" Applies onnxruntime fusion, this parameter should contain the model type or multiple values separated by `|`. `ALL` can be used to run them all. - """.strip( - "\n" - ) - ), + """.strip("\n")), ) parser.add_argument("-v", "--verbose", default=0, type=int, help="verbosity") parser.add_argument("--dtype", help="Changes dtype if necessary.") @@ -626,32 +598,24 @@ def get_parser_validate(name: str = "validate") -> ArgumentParser: "--iop", metavar="KEY=VALUE", nargs="*", - help=textwrap.dedent( - """ + help=textwrap.dedent(""" Additional input options, used to change the default inputs use to export. Examples: --iop cls_cache=SlidingWindowCache --iop cls_cache=StaticCache - """.strip( - "\n" - ) - ), + """.strip("\n")), action=_ParseDict, ) parser.add_argument( "--mop", metavar="KEY=VALUE", nargs="*", - help=textwrap.dedent( - """ + help=textwrap.dedent(""" Additional model options, used to change some parameters of the model. Example: --mop attn_implementation=sdpa --mop attn_implementation=eager" --mop "rope_scaling={'rope_type': 'dynamic', 'factor': 10.0}" - """.strip( - "\n" - ) - ), + """.strip("\n")), action=_ParseDict, ) if name == "validate": @@ -683,42 +647,32 @@ def get_parser_validate(name: str = "validate") -> ArgumentParser: parser.add_argument( "--quiet-input-sets", default="", - help=textwrap.dedent( - """ + help=textwrap.dedent(""" Avoids raising an exception when an input sets does not work with the exported model. Example: --quiet-input-sets=inputs,inputs22 - """.strip( - "\n" - ) - ), + """.strip("\n")), ) parser.add_argument( "--expop", metavar="KEY=VALUE", nargs="*", - help=textwrap.dedent( - """ + help=textwrap.dedent(""" Additional exporter options, use to change some parameters of the model. Examples: --expop report=True --expop report=True --expop verify=True - """.strip( - "\n" - ) - ), + """.strip("\n")), action=_ParseDict, ) parser.add_argument( "--save-ep", default="", - help=textwrap.dedent( - """ + help=textwrap.dedent(""" saves the exported program with torch.export.save and the inputs sets with torch.save, then command line sbs can be used to look for discrepancies. - """ - ), + """), ) return parser @@ -1003,18 +957,15 @@ def __call__(self, parser, namespace, values, option_string=None): def get_parser_agg() -> ArgumentParser: parser = ArgumentParser( prog="agg", - description=textwrap.dedent( - """ + description=textwrap.dedent(""" Aggregates statistics coming from benchmarks. Every run is a row. Every row is indexed by some keys, and produces values. Every row has a date. The data can come any csv files produces by benchmarks, it can concatenates many csv files, or csv files inside zip files. It produces an excel file with many tabs, one per view. - """ - ), - epilog=textwrap.dedent( - """ + """), + epilog=textwrap.dedent(""" examples: python -m onnx_diagnostic agg test_agg.xlsx raw/*.zip -v 1 @@ -1025,8 +976,7 @@ def get_parser_agg() -> ArgumentParser: python -m onnx_diagnostic agg history.xlsx raw/*.csv -v 1 --no-raw \\ --no-recent - """ - ), + """), formatter_class=RawTextHelpFormatter, ) parser.add_argument("output", help="output excel file") @@ -1104,15 +1054,13 @@ def get_parser_agg() -> ArgumentParser: "--views", default="agg-suite,agg-all,disc,speedup,time,time_export,err,cmd," "bucket-speedup,raw-short,counts,peak-gpu,onnx", - help=textwrap.dedent( - """ + help=textwrap.dedent(""" Views to add to the output files. Each view becomes a tab. A view is defined by its name, among agg-suite, agg-all, disc, speedup, time, time_export, err, cmd, bucket-speedup, raw-short, counts, peak-gpu, onnx. Their definition is part of class CubeLogsPerformance. - """ - ), + """), ) parser.add_argument( "--csv", @@ -1134,14 +1082,12 @@ def get_parser_agg() -> ArgumentParser: ) parser.add_argument( "--sbs", - help=textwrap.dedent( - """ + help=textwrap.dedent(""" Defines an exporter to compare to another, there must be at least two arguments defined with --sbs. Example: --sbs dynamo:exporter=onnx-dynamo,opt=ir,attn_impl=eager --sbs custom:exporter=custom,opt=default,attn_impl=eager - """ - ), + """), action=_ParseNamedDict, ) return parser @@ -1205,18 +1151,15 @@ def _cmd_agg(argv: List[Any]): def get_parser_sbs() -> ArgumentParser: parser = ArgumentParser( prog="side-by-side (sbs)", - description=textwrap.dedent( - """ + description=textwrap.dedent(""" Compares the intermediate outputs between the exported program and the exported onnx model. It assumes some names are common. The execution of the exported program and the onnx model are done in parallel. The device is the one used to store the model and the inputs. Where do discrepancies start? This function tries to answer that question. - """ - ), - epilog=textwrap.dedent( - """ + """), + epilog=textwrap.dedent(""" The command line expects the following files to be saved with the following function. inputs is a dictionary of the input of the model. @@ -1231,8 +1174,7 @@ def get_parser_sbs() -> ArgumentParser: model (through the exported program) and its onnx conversion. This functionality dumps everything it can to disk so that it be replayed in a separate process. - """ - ), + """), ) parser.add_argument( "-i", @@ -1246,12 +1188,10 @@ def get_parser_sbs() -> ArgumentParser: "--ep", type=str, required=True, - help=textwrap.dedent( - """ + help=textwrap.dedent(""" exported program saved with torch.export.save, input sets saved with torch.save, - """ - ), + """), ) parser.add_argument( "-m", @@ -1311,25 +1251,21 @@ def get_parser_sbs() -> ArgumentParser: "--second-run", action=BooleanOptionalAction, default=False, - help=textwrap.dedent( - """ + help=textwrap.dedent(""" Tries to run all onnx nodes with torch results produced by the exported program. It then measures the discrepancies again. It can be used to identify kernel introduces discrepancies from other just propagating them. - """ - ), + """), ) parser.add_argument( "--reset", required=False, default="", - help=textwrap.dedent( - """ + help=textwrap.dedent(""" List of result names separated by a comma. For those results, the side-by-side will take torch results instead of onnx results to compute the rest of the onnx model. - """ - ), + """), ) parser.add_argument( "-s", @@ -1365,14 +1301,12 @@ def get_parser_sbs() -> ArgumentParser: "--replay-prefix-model", action=BooleanOptionalAction, default=False, - help=textwrap.dedent( - """ + help=textwrap.dedent(""" There are two ways to recompute an intermediate output, the first one is to " produce the minimal model between torch and onnx. The second one is to dump onnx models from the inputs to the considered intermediate results. This enables the second one. - """ - ), + """), ) return parser @@ -1511,20 +1445,16 @@ def _size(name): def get_parser_compare() -> ArgumentParser: parser = ArgumentParser( prog="compare", - description=textwrap.dedent( - """ + description=textwrap.dedent(""" Compares two onnx models by aligning the nodes between both models. This is done through an edit distance. - """ - ), - epilog=textwrap.dedent( - """ + """), + epilog=textwrap.dedent(""" Each element (initializer, input, node, output) of the model is converted into an observation. Then it defines a distance between two elements. And finally, it finds the best alignment with an edit distance. - """ - ), + """), ) parser.add_argument("model1", type=str, help="first model to compare") parser.add_argument("model2", type=str, help="second model to compare") @@ -1551,15 +1481,12 @@ def get_parser_optimize() -> ArgumentParser: parser = ArgumentParser( prog="optimize", formatter_class=RawTextHelpFormatter, - description=textwrap.dedent( - """ + description=textwrap.dedent(""" Optimizes an onnx model by fusing nodes. It looks for patterns in the graphs and replaces them by the corresponding nodes. It also does basic optimization such as removing identity nodes or unused nodes. - """ - ), - epilog=textwrap.dedent( - """ + """), + epilog=textwrap.dedent(""" The goal is to make the model faster. Argument patterns defines the patterns to apply or the set of patterns. It is possible to show statistics or to remove a particular pattern. @@ -1575,8 +1502,7 @@ def get_parser_optimize() -> ArgumentParser: - PATTERN=: increase verbosity for specific patterns to understand why one pattern was not applied, this shows which line is rejecting a pattern if it seems one pattern was missed - """ - ), + """), ) parser.add_argument( "algorithm", @@ -1608,13 +1534,11 @@ def get_parser_optimize() -> ArgumentParser: parser.add_argument( "--processor", default="", - help=textwrap.dedent( - """ + help=textwrap.dedent(""" optimization for a specific processor, CPU, CUDA or both CPU,CUDA, some operators are only available in one processor, it might be not used with all - """ - ).strip("\n"), + """).strip("\n"), ) parser.add_argument( "--remove-shape-info", @@ -1658,8 +1582,7 @@ def get_main_parser() -> ArgumentParser: prog="onnx_diagnostic", description="onnx_diagnostic main command line.\n", formatter_class=RawTextHelpFormatter, - epilog=textwrap.dedent( - """ + epilog=textwrap.dedent(""" Type 'python -m onnx_diagnostic --help' to get help for a specific command. @@ -1675,8 +1598,7 @@ def get_main_parser() -> ArgumentParser: stats - produces statistics on a model unlighten - restores an onnx model produces by the previous experiment validate - validate a model (knowing its model id on HuggginFace Hub) - """ - ), + """), ) parser.add_argument( "cmd", diff --git a/onnx_diagnostic/ci_models/export_phi4_mm.py b/onnx_diagnostic/ci_models/export_phi4_mm.py index be28c7eb..1cc4b319 100644 --- a/onnx_diagnostic/ci_models/export_phi4_mm.py +++ b/onnx_diagnostic/ci_models/export_phi4_mm.py @@ -1033,16 +1033,14 @@ def forward( if __name__ == "__main__": parser = get_parser( "qwen25", - epilog=textwrap.dedent( - r""" + epilog=textwrap.dedent(r""" Tested command lines:: python -m onnx_diagnostic.ci_models.export_phi4_mm \ -m microsoft/Phi-4-multimodal-instruct \ --device cuda --dtype float16 --exporter custom \ --pretrained --second-input --part vision - """ - ), + """), ) args = parser.parse_args(sys.argv[1:]) main( diff --git a/onnx_diagnostic/export/api.py b/onnx_diagnostic/export/api.py index e19a30fd..dfcd15be 100644 --- a/onnx_diagnostic/export/api.py +++ b/onnx_diagnostic/export/api.py @@ -509,12 +509,10 @@ def make_method(self): simple_sig = inspect.Signature(params, return_annotation=inspect._empty) args = str(simple_sig)[1:-1] calls_args = ", ".join(f"{p}={p}" for p in simple_sig.parameters) - src = textwrap.dedent( - f""" + src = textwrap.dedent(f""" def f(self, {args}): return self._method_call({calls_args}) - """ - ) + """) self._method_src = src ns = {} try: diff --git a/onnx_diagnostic/helpers/bench_run.py b/onnx_diagnostic/helpers/bench_run.py index 64b0e93e..21b72f9c 100644 --- a/onnx_diagnostic/helpers/bench_run.py +++ b/onnx_diagnostic/helpers/bench_run.py @@ -11,7 +11,6 @@ from datetime import datetime from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union - _DEFAULT_STRING_LIMIT = 2000 diff --git a/onnx_diagnostic/helpers/ort_session.py b/onnx_diagnostic/helpers/ort_session.py index 627af24d..a05be803 100644 --- a/onnx_diagnostic/helpers/ort_session.py +++ b/onnx_diagnostic/helpers/ort_session.py @@ -14,7 +14,6 @@ ) from .torch_helper import torch_dtype_to_onnx_dtype - DEVICES = {-1: ORTC.OrtDevice(ORTC.OrtDevice.cpu(), ORTC.OrtDevice.default_memory(), 0)} TensorLike = Union[np.ndarray, torch.Tensor] diff --git a/onnx_diagnostic/reference/evaluator.py b/onnx_diagnostic/reference/evaluator.py index 787f6fc4..bd13cbfb 100644 --- a/onnx_diagnostic/reference/evaluator.py +++ b/onnx_diagnostic/reference/evaluator.py @@ -42,7 +42,6 @@ from .ops.op_transpose_cast import Transpose2DCastFP16, Transpose2DCastFP32 from .ops.op_tri_matrix import TriMatrix - logger = getLogger("onnx-diagnostic-eval") diff --git a/onnx_diagnostic/reference/ort_evaluator.py b/onnx_diagnostic/reference/ort_evaluator.py index ffa511d6..1abcb713 100644 --- a/onnx_diagnostic/reference/ort_evaluator.py +++ b/onnx_diagnostic/reference/ort_evaluator.py @@ -34,7 +34,6 @@ from .report_results_comparison import ReportResultComparison from .evaluator import ExtendedReferenceEvaluator - PROTO = (FunctionProto, ModelProto, GraphProto, NodeProto) Proto = Union[FunctionProto, ModelProto, GraphProto, NodeProto] diff --git a/onnx_diagnostic/reference/report_results_comparison.py b/onnx_diagnostic/reference/report_results_comparison.py index 2cc0f185..eb731ba3 100644 --- a/onnx_diagnostic/reference/report_results_comparison.py +++ b/onnx_diagnostic/reference/report_results_comparison.py @@ -1,6 +1,5 @@ from typing import Any, Dict, List, Tuple, Union - ReportKeyNameType = Union[str, Tuple[str, int, str]] ReportKeyValueType = Tuple[int, Tuple[int, ...]] diff --git a/onnx_diagnostic/tasks/feature_extraction.py b/onnx_diagnostic/tasks/feature_extraction.py index 5bb0af99..d5bde6b1 100644 --- a/onnx_diagnostic/tasks/feature_extraction.py +++ b/onnx_diagnostic/tasks/feature_extraction.py @@ -3,7 +3,6 @@ from ..helpers.config_helper import update_config, check_hasattr from ..helpers.cache_helper import make_dynamic_cache, make_encoder_decoder_cache - __TASK__ = "feature-extraction" diff --git a/onnx_diagnostic/torch_export_patches/__init__.py b/onnx_diagnostic/torch_export_patches/__init__.py index 8a0b4df5..c1c80eb9 100644 --- a/onnx_diagnostic/torch_export_patches/__init__.py +++ b/onnx_diagnostic/torch_export_patches/__init__.py @@ -4,7 +4,6 @@ ) from .patch_module import torch_export_rewrite - # bypass_export_some_errors is the first name given to the patches. bypass_export_some_errors = torch_export_patches # type: ignore diff --git a/onnx_diagnostic/torch_export_patches/serialization/transformers_impl.py b/onnx_diagnostic/torch_export_patches/serialization/transformers_impl.py index e08c4a99..ccfe9940 100644 --- a/onnx_diagnostic/torch_export_patches/serialization/transformers_impl.py +++ b/onnx_diagnostic/torch_export_patches/serialization/transformers_impl.py @@ -22,7 +22,6 @@ from ...helpers.cache_helper import make_dynamic_cache, make_static_cache, CacheKeyValue from . import make_serialization_function_for_dataclass - SUPPORTED_DATACLASSES: Set[type] = set() WRONG_REGISTRATIONS = { DynamicCache: "4.50", diff --git a/onnx_diagnostic/torch_models/code_sample.py b/onnx_diagnostic/torch_models/code_sample.py index 61053aaf..edec9753 100644 --- a/onnx_diagnostic/torch_models/code_sample.py +++ b/onnx_diagnostic/torch_models/code_sample.py @@ -8,11 +8,9 @@ from .hghub import get_untrained_model_with_inputs from .validate import filter_inputs, make_patch_kwargs - CODE_SAMPLES = { "imports": "from typing import Any\nimport torch", - "get_model_with_inputs": textwrap.dedent( - """ + "get_model_with_inputs": textwrap.dedent(""" def get_model_with_inputs( model_id:str, subfolder: str | None = None, @@ -57,8 +55,7 @@ def get_model_with_inputs( if device: data["model"] = data["model"].to(device) return data["model"] - """ - ), + """), } @@ -326,11 +323,9 @@ def code_sample( imports, cache_import, CODE_SAMPLES["get_model_with_inputs"], - textwrap.dedent( - f""" + textwrap.dedent(f""" model = get_model_with_inputs({model_args}) - """ - ), + """), f"inputs = {input_code}", exporter_code, ] diff --git a/onnx_diagnostic/torch_models/hghub/hub_data.py b/onnx_diagnostic/torch_models/hghub/hub_data.py index 054f8ede..1f81980c 100644 --- a/onnx_diagnostic/torch_models/hghub/hub_data.py +++ b/onnx_diagnostic/torch_models/hghub/hub_data.py @@ -10,8 +10,7 @@ "ResNetForImageClassification": dict(image_size=224), } -__data_arch__ = textwrap.dedent( - """ +__data_arch__ = textwrap.dedent(""" architecture,task ASTModel,feature-extraction AutoencoderKL,image-to-image @@ -166,8 +165,7 @@ YolosModel,image-feature-extraction Alibaba-NLP/gte-large-en-v1.5,sentence-similarity emilyalsentzer/Bio_ClinicalBERT,fill-mask - nvidia/Cosmos-Predict2-2B-Video2World//transformer,image-to-video""" -) + nvidia/Cosmos-Predict2-2B-Video2World//transformer,image-to-video""") __data_tasks__ = [ "audio-classification", diff --git a/onnx_diagnostic/torch_models/hghub/hub_data_cached_configs.py b/onnx_diagnostic/torch_models/hghub/hub_data_cached_configs.py index c09124bd..4183c1b9 100644 --- a/onnx_diagnostic/torch_models/hghub/hub_data_cached_configs.py +++ b/onnx_diagnostic/torch_models/hghub/hub_data_cached_configs.py @@ -194,8 +194,7 @@ def _ccached_hf_internal_testing_tiny_random_beitforimageclassification(): def _ccached_hf_internal_testing_tiny_random_convnext(): "hf-internal-testing/tiny-random-convnext" - t64 = textwrap.dedent( - """ + t64 = textwrap.dedent(""" ewogICJhcmNoaXRlY3R1cmVzIjogWwogICAgIkNvbnZOZXh0Rm9ySW1hZ2VDbGFzc2lmaWNhdGlvbiIKI CBdLAogICJkZXB0aHMiOiBbCiAgICAzLAogICAgMywKICAgIDksCiAgICAzCiAgXSwKICAiZHJvcF9wYX RoX3JhdGUiOiAwLjAsCiAgImhpZGRlbl9hY3QiOiAiZ2VsdSIsCiAgImhpZGRlbl9zaXplcyI6IFsKICA @@ -1345,8 +1344,7 @@ def _ccached_hf_internal_testing_tiny_random_convnext(): F0Y2hfc2l6ZSI6IDQsCiAgInN0YWdlX25hbWVzIjogWwogICAgInN0ZW0iLAogICAgInN0YWdlMSIsCiA gICAic3RhZ2UyIiwKICAgICJzdGFnZTMiLAogICAgInN0YWdlNCIKICBdLAogICJ0b3JjaF9kdHlwZSI6 ICJmbG9hdDMyIiwKICAidHJhbnNmb3JtZXJzX3ZlcnNpb24iOiAiNC41MS4wLmRldjAiCn0K - """.strip() - ) + """.strip()) js = base64.b64decode(t64.encode("utf-8")) kwargs = json.loads(js) return transformers.ConvNextConfig(**kwargs) @@ -1817,8 +1815,7 @@ def _ccached_sshleifer_tiny_marian_en_de(): def _ccached_hf_internal_testing_tiny_random_maskformerforinstancesegmentation(): "hf-internal-testing/tiny-random-MaskFormerForInstanceSegmentation" - t64 = textwrap.dedent( - """ + t64 = textwrap.dedent(""" ewogICJhcmNoaXRlY3R1cmVzIjogWwogICAgIk1hc2tGb3JtZXJGb3JJbnN0YW5jZVNlZ21lbnRhdGlvb iIKICBdLAogICJiYWNrYm9uZSI6IG51bGwsCiAgImJhY2tib25lX2NvbmZpZyI6IHsKICAgICJhdHRlbn Rpb25fcHJvYnNfZHJvcG91dF9wcm9iIjogMC4wLAogICAgImRlcHRocyI6IFsKICAgICAgMSwKICAgICA @@ -1866,8 +1863,7 @@ def _ccached_hf_internal_testing_tiny_random_maskformerforinstancesegmentation() b2F0MzIiLAogICJ0cmFuc2Zvcm1lcnNfdmVyc2lvbiI6ICI0LjUxLjAuZGV2MCIsCiAgInVzZV9hdXhpb GlhcnlfbG9zcyI6IGZhbHNlLAogICJ1c2VfcHJldHJhaW5lZF9iYWNrYm9uZSI6IGZhbHNlLAogICJ1c2 VfdGltbV9iYWNrYm9uZSI6IGZhbHNlCn0K - """.strip() - ) + """.strip()) js = base64.b64decode(t64.encode("utf-8")) kwargs = json.loads(js) return transformers.MaskFormerConfig(**kwargs) @@ -1910,8 +1906,7 @@ def _ccached_echarlaix_tiny_random_mistral(): def _ccached_hf_internal_testing_tiny_random_mobilevit(): "hf-internal-testing/tiny-random-mobilevit" - t64 = textwrap.dedent( - """ + t64 = textwrap.dedent(""" ewogICJhcmNoaXRlY3R1cmVzIjogWwogICAgIk1vYmlsZVZpVEZvckltYWdlQ2xhc3NpZmljYXRpb24iC iAgXSwKICAiYXNwcF9kcm9wb3V0X3Byb2IiOiAwLjEsCiAgImFzcHBfb3V0X2NoYW5uZWxzIjogMjU2LA ogICJhdHJvdXNfcmF0ZXMiOiBbCiAgICA2LAogICAgMTIsCiAgICAxOAogIF0sCiAgImF0dGVudGlvbl9 @@ -3064,8 +3059,7 @@ def _ccached_hf_internal_testing_tiny_random_mobilevit(): iAgIm91dHB1dF9zdHJpZGUiOiAzMiwKICAicGF0Y2hfc2l6ZSI6IDIsCiAgInFrdl9iaWFzIjogdHJ1ZS wKICAic2VtYW50aWNfbG9zc19pZ25vcmVfaW5kZXgiOiAyNTUsCiAgInRvcmNoX2R0eXBlIjogImZsb2F 0MzIiLAogICJ0cmFuc2Zvcm1lcnNfdmVyc2lvbiI6ICI0LjUxLjAuZGV2MCIKfQo= - """.strip() - ) + """.strip()) js = base64.b64decode(t64.encode("utf-8")) kwargs = json.loads(js) return transformers.MobileViTConfig(**kwargs) diff --git a/onnx_diagnostic/torch_onnx/compare.py b/onnx_diagnostic/torch_onnx/compare.py index 25e8ac44..11fd75ff 100644 --- a/onnx_diagnostic/torch_onnx/compare.py +++ b/onnx_diagnostic/torch_onnx/compare.py @@ -5,7 +5,6 @@ import onnx from ..helpers.onnx_helper import onnx_dtype_name - _NOT_SO_FAR_OPS = [ {"MatMul", "Gemm", "FusedMatMul"}, {"Conv", "FusedConv"}, diff --git a/onnx_diagnostic/torch_onnx/sbs_dataclasses.py b/onnx_diagnostic/torch_onnx/sbs_dataclasses.py index b0ef5a5e..f9b4e73b 100644 --- a/onnx_diagnostic/torch_onnx/sbs_dataclasses.py +++ b/onnx_diagnostic/torch_onnx/sbs_dataclasses.py @@ -120,8 +120,7 @@ def get_replay_code(self) -> str: rc = ReplayConfiguration(dump_folder="unused") print(rc.get_replay_code()) """ - return textwrap.dedent( - """ + return textwrap.dedent(""" import onnx import torch from onnx_diagnostic.helpers import max_diff, string_diff, string_type @@ -225,8 +224,7 @@ def get_replay_code(self) -> str: sess.run(None, ep_feeds) obj = prof.key_averages() print(obj.table()) - """ - ) + """) def dump( self,