### Build HCCL AllReduce Example Source: https://github.com/ascend/pytorch/blob/master/examples/libtorch_hccl/README_HCCL.md Navigate to the example directory, create a build folder, and use CMake to configure and build the HCCL AllReduce example. Ensure you have CMake and a C++ compiler installed. ```bash cd examples/libtorch_hccl mkdir build && cd build cmake .. make ``` -------------------------------- ### Full Example: Compiling and Running with MLIR Backend Source: https://github.com/ascend/pytorch/blob/master/torch_npu/_inductor/ascend_npu_ir/README.md This example demonstrates setting up the environment, defining a model, and compiling it using the MLIR backend via an environment variable, then capturing and printing the generated MLIR code. ```python import os # 环境变量调用需要在torch_npu初始化之前 os.environ['TORCHINDUCTOR_NPU_BACKEND'] = 'mlir' import torch import torch_npu from torch._inductor.utils import run_and_get_code import torch_npu._inductor import torch import triton # config导入在compile执行之前 torch._inductor.config.npu_backend = "mlir" # 定义模型 def op_calc (x , y): return x * y x = torch.randn((3,), requires_grad=False, dtype=torch.float32, device="npu") y = torch.randn((3,), requires_grad=False, dtype=torch.float32, device="npu") std_out = op_calc(x, y) # options调用,修改compile参数 compile_func = torch.compile(op_calc, options={"npu_backend": "mlir"}) compile_out, codes = run_and_get_code(compile_func,x,y) print(codes[0]) ``` -------------------------------- ### Install PyTorch for x86 Source: https://github.com/ascend/pytorch/blob/master/README.md Use this command to install the PyTorch package for x86 systems. Ensure CANN is installed beforehand. ```shell pip3 install torch==2.1.0+cpu --index-url https://download.pytorch.org/whl/cpu ``` -------------------------------- ### Install pybind11 Source: https://github.com/ascend/pytorch/blob/master/examples/libtorch_triton_ascend/README.md Install the pybind11 library, which is a dependency for this project. ```bash pip install pybind11 ``` -------------------------------- ### Run HCCL AllReduce Example Source: https://github.com/ascend/pytorch/blob/master/examples/libtorch_hccl/README_HCCL.md Execute the HCCL AllReduce example using the provided shell script. Make the script executable before running. ```bash cd examples/libtorch_hccl chmod +x libtorch_hccl.sh ./libtorch_hccl.sh ``` -------------------------------- ### Run HCCL AllReduce Example with Custom Process Count Source: https://github.com/ascend/pytorch/blob/master/examples/libtorch_hccl/README_HCCL.md Run the HCCL AllReduce example with a specified number of processes by setting the NUM_PROCESSES environment variable. ```bash NUM_PROCESSES=4 ./libtorch_hccl.sh ``` -------------------------------- ### Install PyTorch for Aarch64 Source: https://github.com/ascend/pytorch/blob/master/README.md Use this command to install the PyTorch package for Aarch64 systems. Ensure CANN is installed beforehand. ```shell pip3 install torch==2.1.0 ``` -------------------------------- ### Run Demo Scripts Source: https://github.com/ascend/pytorch/blob/master/examples/libtorch_triton_ascend/README.md Execute the provided shell script to run the C++ demo examples. ```bash bash examples/run_demo.sh ``` -------------------------------- ### Install torch-npu Package Source: https://github.com/ascend/pytorch/blob/master/README.md Install the torch-npu package using pip. Ensure PyTorch and its dependencies are installed first. ```shell pip3 install torch-npu==2.1.0.post17 ``` -------------------------------- ### Initialize CANN Environment Source: https://github.com/ascend/pytorch/blob/master/README.md Source the CANN environment script before using Ascend NPU. Change the path if your installation differs. ```Shell # Default path, change it if needed. source /usr/local/Ascend/ascend-toolkit/set_env.sh ``` -------------------------------- ### Install torch-npu Dependencies Source: https://github.com/ascend/pytorch/blob/master/README.md Install necessary Python dependencies for torch-npu. These are pyyaml and setuptools. ```shell pip3 install pyyaml ``` ```shell pip3 install setuptools ``` -------------------------------- ### torch.distributed.elastic.multiprocessing.start_processes Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Function to start multiple processes for distributed training. ```APIDOC ## torch.distributed.elastic.multiprocessing.start_processes ### Description Function to start multiple processes for distributed training. ### Method N/A (Function) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ### Error Handling N/A ``` -------------------------------- ### torch.utils.cpp_extension.get_compiler_abi_compatibility_and_version Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Gets the compiler ABI compatibility and version for C++ extensions. It is compatible with NPU. ```APIDOC ## torch.utils.cpp_extension.get_compiler_abi_compatibility_and_version ### Description Gets the compiler ABI compatibility and version for C++ extensions. This API is compatible with NPU. ### Compatibility - NPU: Y ### Limitations None specified. ``` -------------------------------- ### Compile torch_npu Source: https://github.com/ascend/pytorch/blob/master/docker/builder/README.md Compile the torch_npu library within the Docker container. This example uses Python 3.10. ```Shell cd /home/pytorch bash ci/build.sh --python=3.10 ``` -------------------------------- ### torch.npu.init Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Initializes the NPU device. ```APIDOC ## torch.npu.init ### Description Initializes the NPU device. This should be called before using any NPU functionalities. ### Method NPU API call ### Endpoint N/A (Python function) ### Parameters None ### Request Example ```python torch.npu.init() ``` ### Response #### Success Response None (initializes the device) ### Response Example ```json null ``` ``` -------------------------------- ### CMake: Set PyTorch and NPU Library Paths Source: https://github.com/ascend/pytorch/blob/master/examples/libtorch_npu/CMakeLists.txt Configures the include and link directories for PyTorch and libtorch_npu. Ensure 'torch_path' and 'torch_npu_path' are set to the correct locations of your installations. ```cmake # set the real path set(torch_path "path/to/your/libtorch/for/pytorch") if(NOT EXISTS ${torch_path}) message(FATAL_ERROR "please set correct torch_path") endif() include_directories(${torch_path}/include) link_directories(${torch_path}/lib) # set the real path set(torch_npu_path "path/to/your/libtorch_npu/for/torch_npu") if(NOT EXISTS ${torch_npu_path}) message(FATAL_ERROR "please set correct torch_npu_path") endif() include_directories(${torch_npu_path}/include) link_directories(${torch_npu_path}/lib) ``` -------------------------------- ### Tensor.lerp Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Performs a linear interpolation between tensor `start` and `end` based on theウェイト `weight`. `out = start + weight * (end - start)`. Only supports fp16, fp32, int64, bool data types. ```APIDOC ## Tensor.lerp ### Description Performs a linear interpolation between tensor `start` and `end` based on the weight `weight`. `out = start + weight * (end - start)`. ### Supported Data Types Only support fp16, fp32, int64, bool. ``` -------------------------------- ### torch.utils.tensorboard.writer.SummaryWriter.__init__ Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md The constructor for SummaryWriter is compatible with Torch NPU. ```APIDOC ## torch.utils.tensorboard.writer.SummaryWriter.__init__ ### Description Initializes the SummaryWriter. ### Compatibility - **torch.utils.tensorboard.writer.SummaryWriter.__init__**: Y ### Limitations None specified. ``` -------------------------------- ### Tensor.lerp_ Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md In-place version of Tensor.lerp. Performs a linear interpolation between tensor `start` and `end` based on theウェイト `weight`. `input = start + weight * (end - start)`. Only supports fp16, fp32, int64, bool data types. ```APIDOC ## Tensor.lerp_ ### Description In-place version of Tensor.lerp. Performs a linear interpolation between tensor `start` and `end` based on the weight `weight`. `input = start + weight * (end - start)`. ### Supported Data Types Only support fp16, fp32, int64, bool. ``` -------------------------------- ### Enter Docker Container Source: https://github.com/ascend/pytorch/blob/master/ci/docker/README.md Run a Docker container interactively, mounting the local PyTorch source code path into the container. Replace {code_path} with the actual path to your torch_npu source code. ```Shell docker run -it -v /{code_path}/pytorch:/home/pytorch manylinux-builder:v1 bash ``` -------------------------------- ### Set Torch Installation Directory Source: https://github.com/ascend/pytorch/blob/master/examples/libtorch_hccl/README_HCCL.md Manually specify the installation directory for libtorch if automatic detection fails. This is typically the site-packages/torch directory within your Python environment. ```bash export TORCH_INSTALL_DIR=/path/to/torch # 通常在 site-packages/torch export TORCH_NPU_INSTALL_DIR=/path/to/torch_npu ``` -------------------------------- ### Enter Docker Container Source: https://github.com/ascend/pytorch/blob/master/docker/builder/README.md Enter the manylinux-builder Docker container interactively. Mount the local torch_npu source code path into the container. ```Shell docker run -it -v /{code_path}/pytorch:/home/pytorch manylinux-builder:v1 bash # {code_path} is the torch_npu source code path ``` -------------------------------- ### Build TorchNPU Docker Image Source: https://github.com/ascend/pytorch/blob/master/docker/OVERVIEW.md Build a TorchNPU Docker image with specified versions for PyTorch, CANN, OS, and Python. Ensure all required build arguments are provided. ```bash docker build \ --build-arg TORCH_VERSION=2.10.0 \ --build-arg CHIP_ARCH=a3 \ --build-arg OS=ubuntu \ --build-arg OS_VERSION=22.04 \ --build-arg PY_VERSION=3.11 \ --build-arg CANN_VERSION=9.0.0 \ --build-arg ARCH=arm \ --build-arg PY_TAG=cp311 \ --build-arg TORCH_NPU_RELEASE_TAG=v26.0.0-pytorch2.10.0 \ -t image_name:tag \ -f Dockerfile . ``` -------------------------------- ### torch.distributed.checkpoint.LoadPlanner.set_up_planner Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md This method is part of the LoadPlanner class and is used to set up the planner for loading operations. ```APIDOC ## torch.distributed.checkpoint.LoadPlanner.set_up_planner ### Description This method is part of the LoadPlanner class and is used to set up the planner for loading operations. ### Method Not specified in source ### Endpoint Not specified in source ### Parameters Not specified in source ### Request Example Not specified in source ### Response Not specified in source ``` -------------------------------- ### torch.distributed.fsdp.FullyShardedDataParallel.get_state_dict_type Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Gets the state dictionary type for FSDP. ```APIDOC ## torch.distributed.fsdp.FullyShardedDataParallel.get_state_dict_type ### Description Gets the state dictionary type for FSDP. ### Method Not specified in source ### Endpoint Not specified in source ### Parameters None specified in source ### Request Example None specified in source ### Response None specified in source ``` -------------------------------- ### torch.distributed.get_world_size Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Gets the total number of processes in the world. ```APIDOC ## torch.distributed.get_world_size ### Description Gets the total number of processes participating in the distributed job. This is often referred to as the world size. ### Method N/A (Function call) ### Endpoint N/A ### Parameters None ### Response #### Success Response - **world_size** (int) - The total number of processes in the distributed world. ``` -------------------------------- ### torch.distributed.get_rank Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Gets the rank of the current process in the world. ```APIDOC ## torch.distributed.get_rank ### Description Gets the rank of the current process in the world. The rank is a unique integer identifier for each process in a distributed job. ### Method N/A (Function call) ### Endpoint N/A ### Parameters None ### Response #### Success Response - **rank** (int) - The rank of the current process. ``` -------------------------------- ### torch.jit.script Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Details on the compatibility and limitations of torch.jit.script for NPU. ```APIDOC ## torch.jit.script ### Description Provides information on the compatibility of `torch.jit.script` with NPU. ### Compatibility - NPU Compatibility: Not specified ### Limitations No specific limitations are documented for NPU usage. ``` -------------------------------- ### torch.distributed.checkpoint.StorageWriter.set_up_storage_writer Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Sets up the storage writer for checkpointing operations. This is a method within the StorageWriter class. ```APIDOC ## torch.distributed.checkpoint.StorageWriter.set_up_storage_writer ### Description Sets up the storage writer for checkpointing operations. This is a method within the StorageWriter class. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (Not specified in source) ### Request Example (Not specified in source) ### Response (Not specified in source) ``` -------------------------------- ### torch.backends.cuda.cufft_plan_cache.size Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Gets the size of the CUFFT plan cache. ```APIDOC ## torch.backends.cuda.cufft_plan_cache.size ### Description Gets the current number of plans stored in the CUFFT plan cache. ### Method `size` ### Endpoint torch.backends.cuda.cufft_plan_cache.size ### Parameters None ### Request Example ```python # Example usage (conceptual) cache_size = torch.backends.cuda.cufft_plan_cache.size print(f"CUFFT plan cache size: {cache_size}") ``` ### Response Returns an integer representing the number of plans in the cache. ``` -------------------------------- ### torch.cuda.temperature Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Gets the current temperature of the CUDA device. ```APIDOC ## torch.cuda.temperature ### Description Retrieves the current temperature of the CUDA device. This can be useful for monitoring hardware performance and thermal conditions. ### Method Not specified (assumed to be a function call) ### Endpoint Not applicable (SDK function) ### Parameters None specified ### Request Example ```python import torch # Get the device temperature temperature = torch.cuda.temperature() print(f"Device temperature: {temperature}°C") ``` ### Response The temperature of the CUDA device, typically in degrees Celsius. The exact return type is not specified. ``` -------------------------------- ### torch.nn.init.kaiming_uniform_ Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Initializes the input weights using a Kaiming uniform distribution. ```APIDOC ## torch.nn.init.kaiming_uniform_ ### Description Initializes the input weights using a Kaiming uniform distribution. ### Method N/A (Function call) ### Endpoint N/A ### Parameters N/A (Function parameters not specified in source) ### Request Example N/A ### Response N/A ``` -------------------------------- ### Secondary Development with TorchNPU Image Source: https://github.com/ascend/pytorch/blob/master/docker/OVERVIEW.md Use an existing TorchNPU image as a base for secondary development. Add user software and dependencies using RUN commands. ```dockerfile FROM quay.io/ascend/torch-npu:2.10.0-910b-ubuntu22.04-py3.11 RUN apt update -y && \ apt install gcc ... ... ``` -------------------------------- ### torch.jit.trace Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Details on the compatibility and limitations of torch.jit.trace for NPU. ```APIDOC ## torch.jit.trace ### Description Provides information on the compatibility of `torch.jit.trace` with NPU. ### Compatibility - NPU Compatibility: Y ### Limitations No specific limitations are documented for NPU usage. ``` -------------------------------- ### torch.autograd.backward Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Performs a backward pass starting from the given tensors. ```APIDOC ## torch.autograd.backward ### Description Computes the gradient of the given tensor with respect to the graph. ### Method Not specified (assumed to be a Python function call) ### Endpoint Not applicable (Python API) ### Parameters Not specified in the source text. ### Request Example ```python torch.autograd.backward(tensors, grad_tensors=None, retain_graph=None, create_graph=False) ``` ### Response Not specified in the source text. ``` -------------------------------- ### torch.jit.load Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Loads a traced or scripted module from disk. ```APIDOC ## torch.jit.load ### Description Loads a traced or scripted module from disk. ### Method Not applicable (Python function) ### Endpoint Not applicable (Python function) ### Parameters This function typically takes a file path or file-like object from which to load the module. ### Request Example ```python # Example usage (conceptual) # loaded_module = torch.jit.load('my_module.pt') ``` ### Response Returns the loaded traced or scripted module. ``` -------------------------------- ### torch.cuda.get_allocator_backend Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Gets the current CUDA memory allocator backend. ```APIDOC ## torch.cuda.get_allocator_backend ### Description Gets the current CUDA memory allocator backend. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (Not specified in source) ### Request Example (Not specified in source) ### Response (Not specified in source) ``` -------------------------------- ### torch.cuda.get_rng_state_all Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Gets the random number generator states for all devices. ```APIDOC ## torch.cuda.get_rng_state_all ### Description Retrieves the current states of the random number generators (RNG) across all available CUDA devices. This is useful for reproducible random number generation. ### Method Not specified (assumed to be a function call) ### Endpoint Not applicable (SDK function) ### Parameters None specified ### Request Example ```python import torch # Get RNG states for all devices rng_states = torch.cuda.get_rng_state_all() print(rng_states) ``` ### Response A tuple or list containing the RNG states for each CUDA device. The exact format of the states is not specified. ``` -------------------------------- ### torch.jit.export Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Details on the compatibility and limitations of torch.jit.export for NPU. ```APIDOC ## torch.jit.export ### Description Provides information on the compatibility of `torch.jit.export` with NPU. ### Compatibility - NPU Compatibility: Y ### Limitations No specific limitations are documented for NPU usage. ``` -------------------------------- ### torch.cuda.clock_rate Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Gets the current clock rate of the CUDA device. ```APIDOC ## torch.cuda.clock_rate ### Description Retrieves the current clock rate of the CUDA device. This can indicate the operational speed of the GPU cores. ### Method Not specified (assumed to be a function call) ### Endpoint Not applicable (SDK function) ### Parameters None specified ### Request Example ```python import torch # Get the device clock rate clock_rate = torch.cuda.clock_rate() print(f"Device clock rate: {clock_rate} MHz") ``` ### Response The current clock rate of the CUDA device, typically in MHz. The exact return type is not specified. ``` -------------------------------- ### torch.optim.ASGD Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Documentation for the ASGD optimizer, including methods for registering hooks, saving/loading state, and performing optimization steps. ```APIDOC ## torch.optim.ASGD ### Description Provides documentation for the ASGD optimizer. ### Methods - **register_step_post_hook**: Registers a hook to be called after the step function. - **register_step_pre_hook**: Registers a hook to be called before the step function. - **state_dict**: Returns a dictionary containing the whole state of the optimizer. - **step**: Performs a single optimization step. - **zero_grad**: Zeros out the gradients of all parameters. ``` -------------------------------- ### torch.cuda.power_draw Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Gets the current power draw of the CUDA device. ```APIDOC ## torch.cuda.power_draw ### Description Retrieves the current power draw of the CUDA device. This information is valuable for power consumption analysis and performance tuning. ### Method Not specified (assumed to be a function call) ### Endpoint Not applicable (SDK function) ### Parameters None specified ### Request Example ```python import torch # Get the device power draw power = torch.cuda.power_draw() print(f"Device power draw: {power} Watts") ``` ### Response The current power draw of the CUDA device, typically in Watts. The exact return type is not specified. ``` -------------------------------- ### torch.npu.get_sync_debug_mode Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Gets the synchronization debug mode for NPU operations. ```APIDOC ## torch.npu.get_sync_debug_mode ### Description Retrieves the current synchronization debug mode setting for NPU operations. ### Method NPU API call ### Endpoint N/A (Python function) ### Parameters None ### Request Example ```python mode = torch.npu.get_sync_debug_mode() print(f"Sync debug mode: {mode}") ``` ### Response #### Success Response - **mode** (int) - The current synchronization debug mode. ### Response Example ```json 0 ``` ``` -------------------------------- ### torch.distributed.rpc.RpcBackendOptions.init_method Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Sets or retrieves the initialization method for the RPC backend. ```APIDOC ## torch.distributed.rpc.RpcBackendOptions.init_method ### Description Configures the method used to initialize the RPC backend. ### Method Attribute Access (Setter/Getter) ### Endpoint N/A (Python API) ### Parameters - **init_method** (string): The initialization method string (e.g., 'env://'). ### Response - **init_method** (string): The currently set initialization method. ``` -------------------------------- ### torch.get_num_threads Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Gets the number of threads used for parallel operations. ```APIDOC ## torch.get_num_threads ### Description Gets the number of threads used for parallel operations. ### Method Not specified ### Endpoint Not specified ### Parameters Not specified ### Request Example Not specified ### Response Not specified ``` -------------------------------- ### torch.distributions.bernoulli.Bernoulli.sample Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Samples from the Bernoulli distribution. ```APIDOC ## torch.distributions.bernoulli.Bernoulli.sample ### Description Samples from the Bernoulli distribution. ### Method Not applicable (method call) ### Endpoint Not applicable ### Parameters Not applicable ### Request Example Not applicable ### Response #### Success Response - **sample** (Tensor) - A sample from the distribution. ``` -------------------------------- ### torch.get_num_interop_threads Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Gets the number of interop threads used for parallel operations. ```APIDOC ## torch.get_num_interop_threads ### Description Gets the number of interop threads used for parallel operations. ### Method Not specified ### Endpoint Not specified ### Parameters Not specified ### Request Example Not specified ### Response Not specified ``` -------------------------------- ### torch.fx.GraphModule.__init__ Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md The constructor for torch.fx.GraphModule is available and compatible. ```APIDOC ## torch.fx.GraphModule.__init__ ### Description Initializes a GraphModule. ### Compatibility Compatible (Y) ``` -------------------------------- ### torch.distributed.checkpoint.StorageReader.set_up_storage_reader Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Sets up the storage reader. This method is part of the StorageReader class in PyTorch distributed checkpointing. ```APIDOC ## torch.distributed.checkpoint.StorageReader.set_up_storage_reader ### Description Sets up the storage reader. This method is part of the StorageReader class in PyTorch distributed checkpointing. ### Method Not specified (assumed to be a Python method call) ### Endpoint Not applicable (Python API) ### Parameters Not specified in the source text. ### Request Example Not specified in the source text. ### Response Not specified in the source text. ``` -------------------------------- ### torch.profiler.schedule Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Defines a schedule for profiling, specifying when to start and stop profiling activities. ```APIDOC ## torch.profiler.schedule ### Description Defines a schedule for profiling, specifying when to start and stop profiling activities. ### Method N/A (Function/Class) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ### Error Handling N/A ``` -------------------------------- ### torch.compiler.list_backends Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Lists the available compiler backends for NPU. ```APIDOC ## torch.compiler.list_backends ### Description Lists the available compiler backends for NPU. ### Method Not specified (assumed to be a function call) ### Endpoint Not applicable (SDK function) ### Parameters None explicitly documented. ### Request Example ```python torch.compiler.list_backends() ``` ### Response None explicitly documented. ``` -------------------------------- ### torch.profiler.ProfilerAction Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Represents an action to be taken during profiling, such as starting or stopping data collection. ```APIDOC ## torch.profiler.ProfilerAction ### Description Represents an action to be taken during profiling, such as starting or stopping data collection. ### Method N/A (Enum/Class) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ### Error Handling N/A ``` -------------------------------- ### torch.distributed.elastic.metrics.prof Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Starts or stops profiling for metrics within the distributed elastic module. ```APIDOC ## torch.distributed.elastic.metrics.prof ### Description Starts or stops profiling for metrics within the distributed elastic module. ### Method Not specified (likely a Python function call) ### Endpoint Not applicable (Python API) ### Parameters Not specified in the source text. ### Request Example Not applicable. ### Response Not specified in the source text. ``` -------------------------------- ### torch.nn.ReplicationPad3d Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Documentation for the ReplicationPad3d module in torch.nn. ```APIDOC ## torch.nn.ReplicationPad3d ### Description Documentation for the ReplicationPad3d module in torch.nn. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### CMakeLists.txt for LibTorch ResNet with NPU Source: https://github.com/ascend/pytorch/blob/master/examples/libtorch_resnet/CMakeLists.txt This CMakeLists.txt file sets up the build environment for a LibTorch ResNet project. It finds the required Torch and Torch NPU packages, configures C++ flags, defines the executable, and links the necessary libraries. Ensure the libtorch_npu directory is correctly placed relative to the CMakeLists.txt file. ```cmake cmake_minimum_required(VERSION 3.18 FATAL_ERROR) project(libtorch_resnet) set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/../../libtorch_npu/) find_package(Torch REQUIRED) find_package(Torch_npu REQUIRED) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}") add_executable(libtorch_resnet libtorch_resnet.cpp) target_link_libraries(libtorch_resnet "${TORCH_LIBRARIES}") target_link_libraries(libtorch_resnet "${TORCH_NPU_LIBRARIES}") set_property(TARGET libtorch_resnet PROPERTY CXX_STANDARD 17) ``` -------------------------------- ### torch.fx.Interpreter.get_attr Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Gets an attribute within the interpreter. This method is part of the torch.fx.Interpreter class. ```APIDOC ## torch.fx.Interpreter.get_attr ### Description Gets an attribute within the interpreter. This method is part of the torch.fx.Interpreter class. ### Method N/A (Method within a Python class) ### Endpoint N/A (Python method) ### Parameters N/A (Details not provided in source) ### Request Example N/A ### Response N/A ``` -------------------------------- ### torch.distributed.get_group_rank Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Gets the rank of the current process within a specified process group. ```APIDOC ## torch.distributed.get_group_rank ### Description Gets the rank of the current process within a specified process group. ### Method Not specified (function call) ### Endpoint Not applicable (function call) ### Parameters Not specified in source. ### Response Not specified in source. ``` -------------------------------- ### torch.nn.ReflectionPad3d Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md ReflectionPad3d is supported on NPU. ```APIDOC ## torch.nn.ReflectionPad3d ### Description Pads the input tensor using reflection of the input along the dimension. ``` -------------------------------- ### Node.name Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Gets the name of a Node in the computation graph. This is a property of a Node object. ```APIDOC ## Node.name ### Description Retrieves the identifier or name associated with a specific node within the computational graph. ### Method Not applicable (Python attribute/property) ### Endpoint Not applicable (Python attribute/property) ### Parameters None. ### Request Example ```python # Example usage (conceptual) # node_name = node.name ``` ### Response string: The name of the node. ``` -------------------------------- ### torch.distributed.checkpoint.SavePlanner.set_up_planner Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Sets up the planner for saving operations within the distributed checkpointing module. This method is part of the SavePlanner class. ```APIDOC ## torch.distributed.checkpoint.SavePlanner.set_up_planner ### Description Sets up the planner for saving operations within the distributed checkpointing module. This method is part of the SavePlanner class. ### Method Not specified in source. ### Endpoint Not specified in source. ### Parameters Not specified in source. ### Request Example Not specified in source. ### Response Not specified in source. ERROR HANDLING: Not specified in source. ``` -------------------------------- ### torch.ao.quantization.fx.custom_config.PrepareCustomConfig.from_dict Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Creates a PrepareCustomConfig object from a dictionary. ```APIDOC ## torch.ao.quantization.fx.custom_config.PrepareCustomConfig.from_dict ### Description Creates a PrepareCustomConfig object from a dictionary. ### Method Not specified (likely a static or class method) ### Endpoint Not applicable (Python API) ### Parameters Not specified in the source text. ### Request Example Not applicable. ### Response Not specified in the source text. ERROR HANDLING: Not specified in the source text. ``` -------------------------------- ### torch.nn.ZeroPad1d Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Documentation for the ZeroPad1d module in torch.nn. ```APIDOC ## torch.nn.ZeroPad1d ### Description Documentation for the ZeroPad1d module in torch.nn. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Find Torch Package Source: https://github.com/ascend/pytorch/blob/master/CMakeLists.txt Locates the required Torch package using a specified installation directory. ```cmake set(Torch_DIR ${PYTORCH_INSTALL_DIR}/share/cmake/Torch) FIND_PACKAGE(Torch REQUIRED) ``` -------------------------------- ### torch.jit.ScriptModule Methods Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md This section details various methods available for torch.jit.ScriptModule, which are essential for working with JIT-compiled models on NPU. ```APIDOC ## torch.jit.ScriptModule ### Description Represents a PyTorch module that has been compiled using the TorchScript JIT compiler. ### Methods - **add_module**: Adds a named submodule to the module. - **apply**: Applies a function recursively to all submodules and parameters. - **bfloat16**: Moves all parameters and buffers to bfloat16. - **buffers**: Returns an iterator over module buffers. - **children**: Returns an iterator over immediate children modules. - **code**: Returns the Python source code of the module. - **code_with_constants**: Returns the Python source code and constants of the module. - **compile**: Compiles the module into TorchScript. - **cpu**: Moves all parameters and buffers to the CPU. - **cuda**: Moves all parameters and buffers to the CUDA device. ``` -------------------------------- ### torch.jit.fork Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Details on the compatibility and limitations of torch.jit.fork for NPU. ```APIDOC ## torch.jit.fork ### Description Provides information on the compatibility of `torch.jit.fork` with NPU. ### Compatibility - NPU Compatibility: Not specified ### Limitations No specific limitations are documented for NPU usage. ``` -------------------------------- ### torch.npu.get_rng_state Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Gets the current random number generator state for NPU. This is the NPU equivalent of torch.cuda.get_rng_state. ```APIDOC ## torch.npu.get_rng_state ### Description Gets the current random number generator state for NPU. This is the NPU equivalent of torch.cuda.get_rng_state. ### Method Not Applicable (Python function) ### Endpoint Not Applicable (Python function) ### Parameters This function does not explicitly list parameters in the provided documentation. ### Request Example ```python # Example usage # rng_state = torch.npu.get_rng_state() ``` ### Response Returns the current state of the NPU random number generator. ``` -------------------------------- ### Build Triton Runtime Library Source: https://github.com/ascend/pytorch/blob/master/examples/libtorch_triton_ascend/README.md Compile the Triton runtime shared library. Navigate to the triton_runtime directory and execute the build script. ```bash cd triton_runtime bash build.sh cd .. ``` -------------------------------- ### torch.distributed.get_global_rank Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Gets the global rank of the current process. This is the rank of the process within the entire distributed job. ```APIDOC ## torch.distributed.get_global_rank ### Description Gets the global rank of the current process. This is the rank of the process within the entire distributed job. ### Method Not specified (function call) ### Endpoint Not applicable (function call) ### Parameters Not specified in source. ### Response Not specified in source. ``` -------------------------------- ### torch.__config__.show Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Displays the current configuration settings for PyTorch, indicating compatibility with NPU. ```APIDOC ## torch.__config__.show ### Description Displays the current configuration settings for PyTorch. ### Method ```python torch.__config__.show() ``` ### Parameters None ### Response Outputs configuration details. ### Example ```python torch.__config__.show() ``` ``` -------------------------------- ### torch.nn.ZeroPad3d Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Documentation for the ZeroPad3d module in torch.nn. ```APIDOC ## torch.nn.ZeroPad3d ### Description Documentation for the ZeroPad3d module in torch.nn. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### torch.distributed.fsdp.FullyShardedDataParallel.state_dict_type Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Gets the current state dictionary type for FullyShardedDataParallel. This indicates how the state is managed (e.g., sharded, replicated). ```APIDOC ## torch.distributed.fsdp.FullyShardedDataParallel.state_dict_type ### Description Gets the current state dictionary type for FullyShardedDataParallel. This property reflects the configuration of how the model's state is stored and accessed, which is essential for understanding checkpointing behavior. ### Method Not specified (assumed to be a method call within a Python script) ### Endpoint N/A (Python API) ### Parameters N/A (Python API) ### Request Example N/A (Python API) ### Response N/A (Python API) ``` -------------------------------- ### EtcdStore Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md An Etcd-based store for distributed coordination. Provides methods for adding, checking, getting, setting, and waiting for data. ```APIDOC ## torch.distributed.elastic.rendezvous.etcd_store.EtcdStore ### Description An implementation of a distributed store using Etcd, used for rendezvous coordination. ### Methods - **add**: Adds data to the store. - **check**: Checks for the existence of data in the store. - **get**: Retrieves data from the store. - **set**: Sets data in the store. - **wait**: Waits for specific conditions or data in the store. (Detailed method signatures and parameters are not provided in the source.) ``` -------------------------------- ### torch.package.PackageExporter.__init__ Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Initializes a PackageExporter object. ```APIDOC ## torch.package.PackageExporter.__init__ ### Description Constructor for the PackageExporter class. Initializes the exporter with necessary configurations. ### Compatibility Y ### Limitations None specified. ``` -------------------------------- ### torch.jit.ScriptModule Methods Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md This section details various methods available for torch.jit.ScriptModule objects, indicating their NPU compatibility. ```APIDOC ## torch.jit.ScriptModule.inlined_graph ### Description Provides access to the inlined graph of a ScriptModule. ### Method N/A (Attribute/Property) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## torch.jit.ScriptModule.ipu ### Description Indicates if the ScriptModule is compatible with or utilizes IPU (Intelligence Processing Unit) features. ### Method N/A (Attribute/Property) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## torch.jit.ScriptModule.load_state_dict ### Description Loads the state dictionary into the ScriptModule. ### Method N/A (Method) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## torch.jit.ScriptModule.modules ### Description Returns an iterator over all submodules in the module. ### Method N/A (Method) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## torch.jit.ScriptModule.named_buffers ### Description Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself. ### Method N/A (Method) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## torch.jit.ScriptModule.named_children ### Description Returns an iterator over immediate children of this module, yielding both the name of the child as well as the child module. ### Method N/A (Method) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## torch.jit.ScriptModule.named_modules ### Description Returns an iterator over all modules in the module, yielding both the name of the module, as well as the module itself. ### Method N/A (Method) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## torch.jit.ScriptModule.named_parameters ### Description Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself. ### Method N/A (Method) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## torch.jit.ScriptModule.parameters ### Description Returns an iterator over module parameters. ### Method N/A (Method) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## torch.jit.ScriptModule.register_backward_hook ### Description Registers a backward hook on the module. ### Method N/A (Method) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Tensor.int_repr Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Returns the integer representation of a tensor. This method provides a way to get the raw integer value of tensor elements. ```APIDOC ## Tensor.int_repr ### Description Returns the integer representation of a tensor. This method provides a way to get the raw integer value of tensor elements. ### Method Not specified, typically a method call on a Tensor object. ### Endpoint Not applicable (SDK method). ### Parameters Not specified in the source text. ### Request Example Not specified in the source text. ### Response Not specified in the source text. ``` -------------------------------- ### torch.fx.wrap Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md torch.fx.wrap is available and compatible. ```APIDOC ## torch.fx.wrap ### Description Utility for wrapping objects in PyTorch FX. ### Compatibility Compatible (Y) ``` -------------------------------- ### torch.nn.init.kaiming_normal_ Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Initializes the input weights using a Kaiming normal distribution. ```APIDOC ## torch.nn.init.kaiming_normal_ ### Description Initializes the input weights using a Kaiming normal distribution. ### Method N/A (Function call) ### Endpoint N/A ### Parameters N/A (Function parameters not specified in source) ### Request Example N/A ### Response N/A ``` -------------------------------- ### torch.nn.SyncBatchNorm.convert_sync_batchnorm Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md A utility function to convert existing BatchNorm layers to SyncBatchNorm layers. This is useful for migrating models to a distributed training setup. ```APIDOC ## torch.nn.SyncBatchNorm.convert_sync_batchnorm ### Description Converts existing BatchNorm layers to SyncBatchNorm layers, facilitating migration to distributed training environments. ### Method N/A (Static method or class method) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Compile torch_npu for Python 3.9 Source: https://github.com/ascend/pytorch/blob/master/ci/docker/README.md Compile torch_npu within the Docker container. This example uses Python 3.9. Ensure you are in the /home/pytorch directory. ```Shell cd /home/pytorch bash ci/build.sh --python=3.9 ``` -------------------------------- ### torch.ao.quantization.prepare_qat Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Prepares a PyTorch model for Quantization-Aware Training (QAT). ```APIDOC ## torch.ao.quantization.prepare_qat ### Description Prepares a PyTorch model for Quantization-Aware Training (QAT). ### Method Not applicable (Python function) ### Endpoint Not applicable (Python function) ### Parameters This function prepares the model for QAT. Specific parameters are not detailed in the source. ### Request Example Not applicable (Python function) ### Response Returns the QAT-prepared PyTorch model. #### Success Response (200) Not applicable (Python function) #### Response Example Not applicable (Python function) ``` -------------------------------- ### Check for libpython*.so Source: https://github.com/ascend/pytorch/blob/master/examples/libtorch_triton_ascend/README.md Verify the presence of the shared Python library, which is required for compilation. This command lists the library in the Python installation's lib directory. ```bash ls $(python3 -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))")/libpython*.so ``` -------------------------------- ### torch.nn.ConstantPad3d Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Documentation for the ConstantPad3d module in torch.nn. ```APIDOC ## torch.nn.ConstantPad3d ### Description Documentation for the ConstantPad3d module in torch.nn. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### torch.jit.trace_module Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Details on the compatibility and limitations of torch.jit.trace_module for NPU. ```APIDOC ## torch.jit.trace_module ### Description Provides information on the compatibility of `torch.jit.trace_module` with NPU. ### Compatibility - NPU Compatibility: Y ### Limitations No specific limitations are documented for NPU usage. ``` -------------------------------- ### PyTorch Ascend NPU Project Architecture Source: https://github.com/ascend/pytorch/blob/master/CONTRIBUTING.md Provides an overview of the directory structure for the PyTorch Ascend NPU project, illustrating the organization of core modules, tools, and examples. ```text pytorch ├── docs/ # 项目文档 ├── ci/ # CI 构建脚本 ├── tools/ # 开发工具 ├── cmake/ # CMake 配置 ├── torch_npu/ # NPU 核心适配模块 │ ├── csrc/ # C++ 后端实现 │ ├── distributed/ # 分布式 Python 接口 │ ├── _inductor/ # Inductor 后端适配 │ ├── dynamo/ # Dynamo 编译器适配 │ ├── npu/ # NPU Python 接口 │ ├── profiler/ # 性能分析 Python 接口 │ ├── _afd/ # AFD Python 接口 │ ├── _logging/ # 日志模块 Python 接口 │ ├── asd/ # 异步检测工具 │ ├── contrib/ # 贡献的扩展模块 │ ├── onnx/ # ONNX 适配 │ └── optim/ # 优化器适配 ├── third_party/ # 第三方依赖 ├── torchnpugen/ # 代码生成工具 ├── examples/ # 示例代码 └── test/ # 测试用例 ``` -------------------------------- ### torch.nn.ReflectionPad1d Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md ReflectionPad1d is supported on NPU. It only supports fp16, fp32, int64, and bool data types. ```APIDOC ## torch.nn.ReflectionPad1d ### Description Pads the input tensor using reflection of the input along the dimension. ### Supported Data Types - fp16 - fp32 - int64 - bool ``` -------------------------------- ### torch.monitor.Event.__init__ Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Initializes a new instance of the Event class. ```APIDOC ## torch.monitor.Event.__init__ ### Description Initializes a new instance of the Event class. ### Method `__init__` ``` -------------------------------- ### Compile torch-npu with Specific Python Version Source: https://github.com/ascend/pytorch/blob/master/README.md Execute the build script within the Docker container for a specified Python version. For example, use --python=3.8 for Python 3.8. ```shell cd /home/pytorch bash ci/build.sh --python=3.8 ``` -------------------------------- ### torch.ao.quantization.prepare Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Prepares a PyTorch model for post-training quantization. ```APIDOC ## torch.ao.quantization.prepare ### Description Prepares a PyTorch model for post-training quantization. ### Method Not applicable (Python function) ### Endpoint Not applicable (Python function) ### Parameters This function takes the PyTorch model as input and prepares it for quantization. Specific parameters are not detailed in the source. ### Request Example Not applicable (Python function) ### Response Returns the prepared PyTorch model. #### Success Response (200) Not applicable (Python function) #### Response Example Not applicable (Python function) ``` -------------------------------- ### Compile torch-npu with Specific PyTorch Version Source: https://github.com/ascend/pytorch/blob/master/README.md Build torch-npu against a specific PyTorch version using the --torch flag. The installed PyTorch version must match the specified version. ```shell bash ci/build.sh --python=3.8 --torch=2.10.0 ``` -------------------------------- ### torch.jit.wait Source: https://github.com/ascend/pytorch/blob/master/docs/api/torch_npu_apis.md Details on the compatibility and limitations of torch.jit.wait for NPU. ```APIDOC ## torch.jit.wait ### Description Provides information on the compatibility of `torch.jit.wait` with NPU. ### Compatibility - NPU Compatibility: Not specified ### Limitations No specific limitations are documented for NPU usage. ``` -------------------------------- ### Compile torch_npu for a Specific PyTorch Version Source: https://github.com/ascend/pytorch/blob/master/ci/docker/README.md Compile torch_npu for a specific PyTorch version. The installed PyTorch version must match the one specified with the --torch argument. Supported versions include 2.10.0, 2.11.0, and 2.12.0. ```Shell bash ci/build.sh --python=3.9 --torch=2.11.0 ```