pypto.frontend.function

Applicable Products

  • Ascend 950PR/Ascend 950DT: Supported
  • Atlas A3 training products/Atlas A3 inference products: Supported
  • Atlas A2 training products/Atlas A2 inference products: Supported

Description

pypto.frontend.function is used to define reusable computation subgraphs or function modules, allowing the same computation logic to be reused across multiple kernel functions. This feature is intended to improve code modularity and maintainability.

Expected features:

  • Code reuse: Encapsulate common computation patterns as functions.
  • Modular design: Combine multiple small functions when building complex operators.
  • Type safety: Input and output types are explicitly specified in the function signature.
  • Automatic optimization: The compiler can inline or optimize function calls.

Prototype

@pypto.frontend.function
def reusable_function(
    arg1: pypto.Tensor,
    arg2: pypto.Tensor,
    ...
) -> pypto.Tensor:
    ...

Parameters

No parameters are configured. The decorator is applied directly to the function.

Return Value

Returns the decorated reusable function object.

Constraints

  1. Only function calls are supported; method calls are not supported.
  2. Parameters: Provide the complete number of parameters (no default values) and pass them strictly in the declared order (no out-of-order or keyword arguments).
  3. Recursive functions are not supported.

Differences from pypto.frontend.jit

Featurepypto.frontend.jitpypto.frontend.function
PurposeDefines an executable kernel functionDefines a reusable sub-function
CompilationCompiled into a complete computation graphInlined or optimized as a subgraph
CallCan be directly called externallyCan only be called within a JIT function
ExecutionIndependent execution unitEmbedded into the parent function for execution