Home / Function/ cast_to() — pytorch Function Reference

cast_to() — pytorch Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  bbf77550_9fd0_5fa7_61ba_9de1b1cde65f["cast_to()"]
  e789c0d4_b1f7_d69d_736c_fb5c020174d2["cast_to_bf16()"]
  e789c0d4_b1f7_d69d_736c_fb5c020174d2 -->|calls| bbf77550_9fd0_5fa7_61ba_9de1b1cde65f
  9e3d0bf0_1f54_f3db_4072_b52d57cefb52["cast_to_fp16()"]
  9e3d0bf0_1f54_f3db_4072_b52d57cefb52 -->|calls| bbf77550_9fd0_5fa7_61ba_9de1b1cde65f
  9bd4562a_1ec6_51d8_c28f_de00fc66199a["cast_to_fp64()"]
  9bd4562a_1ec6_51d8_c28f_de00fc66199a -->|calls| bbf77550_9fd0_5fa7_61ba_9de1b1cde65f
  966e8ab0_98c7_2f6a_55eb_0fa446f905f8["cast_to_fp32()"]
  966e8ab0_98c7_2f6a_55eb_0fa446f905f8 -->|calls| bbf77550_9fd0_5fa7_61ba_9de1b1cde65f
  style bbf77550_9fd0_5fa7_61ba_9de1b1cde65f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

benchmarks/dynamo/common.py lines 1679–1695

def cast_to(dtype, model, inputs):
    # cast model and inputs to fp16
    if dtype == torch.float16:
        model = model.half()
    else:
        model = model.to(dtype)

    def cast_and_preserve_markings(x):
        if not isinstance(x, torch.Tensor) or not x.is_floating_point():
            return x
        y = x.to(dtype)
        # Preserve dynamic/unbacked markings
        copy_dynamo_tensor_attributes(x, y)
        return y

    inputs = tree_map(cast_and_preserve_markings, inputs)
    return model, inputs

Subdomains

Frequently Asked Questions

What does cast_to() do?
cast_to() is a function in the pytorch codebase.
What calls cast_to()?
cast_to() is called by 4 function(s): cast_to_bf16, cast_to_fp16, cast_to_fp32, cast_to_fp64.

Analyze Your Own Codebase

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

Try Supermodel Free