PyTorch adds Meta kernels to fix hardtanh export
Export no longer fails on inverted bounds with new Meta dispatch.
PyTorch’s latest PR #185298 resolves a subtle inconsistency in the `torch.export` pipeline. When exporting models using `aten.hardtanh`, the export path would fail if the activation bounds were inverted (i.e., `min_val > max_val`). Native ATen allowed this legacy behavior (delegating to clamping), but the decomposition used by `FakeTensor`/Meta dispatch—which follows the Python frontend—correctly rejects it. This divergence caused export to reject models that eager execution accepted.
The fix adds dedicated Meta kernels for `aten.hardtanh`, `aten.hardtanh.out`, and `aten.hardtanh_`. These kernels replicate ATen’s validation and execution logic, including handling of bool/complex inputs, integer scalar conversion, unsigned negative limits, out device/dtype errors, scalar range checks, and resized out strides. This avoids breaking backward compatibility in the eager path and keeps `torch.nn.functional.hardtanh` distinct from `torch.ops.aten.hardtanh`. Tests have been added to `test_meta.py` and `test_export.py` to ensure the fix is robust.
- Adds Meta kernels for `aten.hardtanh`, `.out`, and in-place variants to match ATen semantics.
- Fixes torch.export failures on inverted bounds (min_val > max_val) without breaking eager behavior.
- Scoped to Meta/FakeTensor dispatch only, preserving the Python frontend’s stricter validation.
Why It Matters
Ensures torch.export is consistent with eager execution, preventing silent model failures in production pipelines.