Developer Tools

trunk/5d6292dfff853cd0559300c88d7330752c185e40: [Native DSL] Add torch.backends.python_native (#178902)

Meta's PyTorch introduces new backend API giving developers granular control over domain-specific language operations.

Deep Dive

Meta's PyTorch team has introduced a significant new backend control API in commit 5d6292d, adding `torch.backends.python_native` to provide developers with unprecedented granular control over domain-specific language (DSL) operations. This new interface allows for both per-DSL and module-level management of Python-native operation overrides that were previously defined in `torch._native`. The addition represents a major step forward in making PyTorch's internal DSL machinery more accessible and controllable for advanced users working with custom operations.

The new API offers two primary control mechanisms. At the per-DSL level, developers can now check properties like `.name`, `.available`, and `.version`, while dynamically enabling or disabling specific DSLs using `.enable()` and `.disable()` methods. At the module level, the API provides broader control through methods like `.get_dsl_operations()` and `.disable_operations()`, along with context managers for temporary operation disabling. This fine-grained control enables better optimization workflows, debugging capabilities, and performance tuning for specialized use cases.

Developed by Simon Layton at Meta, this feature includes comprehensive tests (`test/python_native/test_torch_backends.py`) and documentation, ensuring reliability and ease of adoption. The implementation follows PyTorch's established patterns for backend control while extending them to the relatively new domain of Python-native DSL operations. This represents PyTorch's continued evolution toward providing enterprise-grade control surfaces for production AI workloads.

Key Points
  • Adds `torch.backends.python_native` API for controlling DSL operations via properties and methods
  • Enables per-DSL control with `.enable()`, `.disable()`, and context managers for temporary changes
  • Includes comprehensive testing via pytest and documentation for production reliability

Why It Matters

Gives PyTorch developers fine-grained control over custom operations, enabling better optimization and debugging for production AI systems.