Nano Banana Pro
Agent skill for nano-banana-pro
This is the PyTorch machine learning framework codebase. These instructions help AI agents navigate and contribute effectively.
Sign in to like and favorite skills
This is the PyTorch machine learning framework codebase. These instructions help AI agents navigate and contribute effectively.
aten/src/ATen/native/ - Modern operator implementations (CPU/CUDA/MPS/sparse)aten/src/ATen/native/native_functions.yaml - Critical: Declarative operator registrytorch/csrc/ - C++ Python bindings (hand-written and generated)torch/csrc/autograd/ - Reverse-mode automatic differentiationtorch/csrc/jit/ - TorchScript JIT compilernative_functions.yamlMost operator changes require editing
, not direct C++ files. This YAML file:native_functions.yaml
torchgen/ to generate C++/Python bindingsbuild/aten/src/ATen/ during compilationExample entry structure:
- func: my_op(Tensor self, Scalar alpha=1) -> Tensor variants: function, method dispatch: CPU: my_op_cpu CUDA: my_op_cuda
After editing
native_functions.yaml, implement kernels in aten/src/ATen/native/ (see aten/src/ATen/native/README.md).
Never run
directly - use pip with editable install:setup.py
python -m pip install --no-build-isolation -v -e .
Speed up builds:
DEBUG=1 - Debug symbols with -g -O0USE_CUDA=0 - Skip CUDA compilationBUILD_TEST=0 - Skip C++ test binariesninja (pip install ninja) for faster buildsccache for incremental compilation cachingRebuild specific targets:
(cd build && ninja <target>)
Critical: DO NOT run entire test suites. Run specific tests only:
python test/test_torch.py TestTorch.test_specific_case
Test structure: All tests use
torch.testing._internal.common_utils:
from torch.testing._internal.common_utils import run_tests, TestCase class TestFeature(TestCase): def test_something(self): # Use self.assertEqual for tensor comparisons pass if __name__ == "__main__": run_tests()
For bug fixes: Create a standalone reproduction script first, verify it fails, then fix and add to appropriate test file.
Run linter (not pre-commit):
lintrunner -a (auto-applies fixes)
StorageImpl.data may be nullptr for unallocated outputs)torch/csrc/)Python.h first to avoid _XOPEN_SOURCE redefinition errorspybind11::gil_scoped_acquire before calling Python API or using THPObjectPtrHANDLE_TH_ERRORS / END_HANDLE_TH_ERRORS for exception conversionCompositeExplicitAutograd dispatch when writing device-agnostic compound opsaten/src/ATen/native/README.md for dispatch keyword guidanceWhen preparing PRs from this environment:
git stash -u git reset --hard $(cat /tmp/orig_work.txt) # Reset to LOCAL branch git stash pop # Resolve conflicts if necessary
build/, don't edit it. Edit the source template or native_functions.yamlTORCH_API macros for exported symbols (required on Windows, optional on Linux)AGENTS.md - Instructions specific to AI coding agentsCONTRIBUTING.md - Comprehensive human contributor guideGLOSSARY.md - Terminology (ATen, kernels, operations, JIT, TorchScript)aten/src/ATen/native/README.md - Operator implementation guidetools/autograd/derivatives.yaml - Gradient definitions for autogradUse
TORCH_SHOW_CPP_STACKTRACES=1 for C++ traces in Python errors. For profiling, prefer py-spy over manual instrumentation.