Home / Function/ run_one_model() — pytorch Function Reference

run_one_model() — pytorch Function Reference

Architecture documentation for the run_one_model() function in common.py from the pytorch codebase.

Entity Profile

Dependency Diagram

graph TD
  9bf8449e_2d7f_c370_514b_b3c7bf20f8e1["run_one_model()"]
  c9be2096_e6d7_2374_ad2e_a6e33f435ada["run()"]
  c9be2096_e6d7_2374_ad2e_a6e33f435ada -->|calls| 9bf8449e_2d7f_c370_514b_b3c7bf20f8e1
  79f63331_206c_51dc_bfd1_4fd84b939754["check_accuracy()"]
  9bf8449e_2d7f_c370_514b_b3c7bf20f8e1 -->|calls| 79f63331_206c_51dc_bfd1_4fd84b939754
  d825b76f_2b85_74b9_6e8c_af36be54ac1f["minify_model()"]
  9bf8449e_2d7f_c370_514b_b3c7bf20f8e1 -->|calls| d825b76f_2b85_74b9_6e8c_af36be54ac1f
  0f41377a_e71d_fd3c_1974_a0ef9ec1158e["check_tolerance()"]
  9bf8449e_2d7f_c370_514b_b3c7bf20f8e1 -->|calls| 0f41377a_e71d_fd3c_1974_a0ef9ec1158e
  c52cc8f1_b576_9d50_98d9_34f721215c0e["run_performance_test_non_alternate()"]
  9bf8449e_2d7f_c370_514b_b3c7bf20f8e1 -->|calls| c52cc8f1_b576_9d50_98d9_34f721215c0e
  d162fe35_2cc5_7738_ed94_76ad697846ef["run_performance_test()"]
  9bf8449e_2d7f_c370_514b_b3c7bf20f8e1 -->|calls| d162fe35_2cc5_7738_ed94_76ad697846ef
  d39825cb_6f16_dc2a_bb05_5c6f3e7a150a["maybe_preserve_compile_debug()"]
  9bf8449e_2d7f_c370_514b_b3c7bf20f8e1 -->|calls| d39825cb_6f16_dc2a_bb05_5c6f3e7a150a
  f00a6213_f2a3_0eef_9451_ee5a24d1ab9f["get_dynamo_stats()"]
  9bf8449e_2d7f_c370_514b_b3c7bf20f8e1 -->|calls| f00a6213_f2a3_0eef_9451_ee5a24d1ab9f
  06ff896d_4db0_aa47_b3cd_be1da620f0ea["empty_gpu_cache()"]
  9bf8449e_2d7f_c370_514b_b3c7bf20f8e1 -->|calls| 06ff896d_4db0_aa47_b3cd_be1da620f0ea
  3473d1a5_c1f5_fc97_006e_79a1d3081bef["write_outputs()"]
  9bf8449e_2d7f_c370_514b_b3c7bf20f8e1 -->|calls| 3473d1a5_c1f5_fc97_006e_79a1d3081bef
  bf029f88_db70_e8df_06de_66d5b0f31c56["print_summary()"]
  9bf8449e_2d7f_c370_514b_b3c7bf20f8e1 -->|calls| bf029f88_db70_e8df_06de_66d5b0f31c56
  style 9bf8449e_2d7f_c370_514b_b3c7bf20f8e1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

benchmarks/dynamo/common.py lines 3004–3102

    def run_one_model(
        self,
        name,
        model,
        example_inputs,
        optimize_ctx,
        experiment,
        explain=False,
        tag=None,
        batch_size=None,
    ):
        mode = "train" if self.args.training else "eval"
        msg = f"{current_device:4} {mode:5} {current_name:34} "
        if tag:
            msg += f" {tag:26}"
        print(msg, flush=True)

        start_stats = get_dynamo_stats()

        if self.args.accuracy:
            status = self.check_accuracy(
                name, model, example_inputs, optimize_ctx, experiment, tag
            )
            print(status)
            if status == "fail_accuracy" and self.args.minify:
                self.minify_model(
                    name, model, example_inputs, optimize_ctx, experiment, tag
                )
        elif self.args.tolerance:
            status = self.check_tolerance(name, model, example_inputs, optimize_ctx)
            print(status)
        elif self.args.performance:
            if self.args.backend in ["torchao", "optimus"]:
                status = self.run_performance_test_non_alternate(
                    name, model, example_inputs, optimize_ctx, experiment, tag
                )
            else:
                status = self.run_performance_test(
                    name,
                    model,
                    example_inputs,
                    optimize_ctx,
                    experiment,
                    tag,
                    batch_size=batch_size,
                )
            print(status)
        empty_gpu_cache(current_device)

        self.maybe_preserve_compile_debug(name, status)

        if self.args.timing:
            from torch._dynamo.utils import op_count, print_time_report
            from torch.utils._stats import simple_call_counter

            print_time_report()
            stats = "STATS: "
            stats = stats + " | ".join(
                itertools.chain(
                    [f"call_* op count: {op_count}"],
                    (f"{key}:{value}" for key, value in simple_call_counter.items()),
                )
            )
            print(stats)
        stats = get_dynamo_stats()
        stats.subtract(start_stats)

        if explain:
            print(
                f"Dynamo produced {stats['unique_graphs']} graphs "
                f"covering {stats['calls_captured']} ops with "
                f"{stats['graph_breaks']} graph breaks ({stats['unique_graph_breaks']} unique)"
            )

        if explain or self.args.log_graph_breaks or self.args.print_graph_breaks:
            filename = f"{output_filename.rstrip('.csv')}_graph_breaks.csv"

            def add_double_quotes(x):
                # Delimiter because reason could have comma
                return f'"{x}"'

            for graph_break in graph_break_reasons:
                reason = add_double_quotes(graph_break.reason)
                user_stack = add_double_quotes(
                    ", ".join([str(x) for x in graph_break.user_stack])
                )

                # NB: Don't upload them to the benchmark database as they are debugging
                # information. There are also around a million records a day which is
                # wasteful to store
                write_outputs(
                    filename,
                    ["model", "reason", "user_stack"],
                    [current_name, reason, user_stack],
                    False,
                )

        if self.args.stats:
            Stats.print_summary()

Subdomains

Called By

Frequently Asked Questions

What does run_one_model() do?
run_one_model() is a function in the pytorch codebase.
What does run_one_model() call?
run_one_model() calls 10 function(s): check_accuracy, check_tolerance, empty_gpu_cache, get_dynamo_stats, maybe_preserve_compile_debug, minify_model, print_summary, run_performance_test, and 2 more.
What calls run_one_model()?
run_one_model() is called by 1 function(s): run.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free