Skip to content

nn.functional.pad fails to compile on CUDA in case we use "replicate mode" and deterministic algorithms #170079

@denix56

Description

@denix56

🐛 Describe the bug

When I try to compile padding with replication on CUDA and have deterministic algorithms ON it fails to compile with this error, I use Torch 2.9.1:

---------------------------------------------------------------------------
Unsupported                               Traceback (most recent call last)
[/tmp/ipython-input-2967465703.py](https://14vcfr3m8vzh-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab-external_20251208-060051_RC00_841635590#) in <cell line: 0>()
      3 pad = torch.nn.ReplicationPad1d(2).to('cuda:0')
      4 a = torch.compile(pad, fullgraph=True)
----> 5 a(torch.zeros(3, 3, device='cuda:0'))

3 frames
[/usr/local/lib/python3.12/dist-packages/torch/_dynamo/eval_frame.py](https://14vcfr3m8vzh-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab-external_20251208-060051_RC00_841635590#) in compile_wrapper(*args, **kwargs)
    839                         cur_exn.__cause__.with_traceback(None)
    840                         cur_exn = cur_exn.__cause__
--> 841                     raise e.with_traceback(None) from e.__cause__  # User compiler error
    842                 except ShortenTraceback as e:
    843                     # Failures in the backend likely don't have useful

Unsupported: Attempted to call function marked as skipped
  Explanation: Dynamo developers have intentionally marked that the function `_gcd_import` in file `<frozen importlib._bootstrap>` should not be traced.
  Hint: Avoid calling the function `_gcd_import`.
  Hint: Apply `@torch._dynamo.dont_skip_tracing` to the function `_gcd_import` to force tracing into the function. More graph breaks may occur as a result of attempting to trace into the function.
  Hint: Please file an issue to PyTorch.

  Developer debug context: module: _frozen_importlib, qualname: _gcd_import, skip reason: <missing reason>

 For more details about this graph break, please visit: https://meta-pytorch.github.io/compile-graph-break-site/gb/gb0007.html

from user code:
   File "/usr/local/lib/python3.12/dist-packages/torch/_dynamo/external_utils.py", line 68, in inner
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.12/dist-packages/torch/nn/modules/padding.py", line 532, in forward
    return F.pad(input, self.padding, "replicate")
  File "/usr/local/lib/python3.12/dist-packages/torch/nn/functional.py", line 5291, in pad
    return importlib.import_module(
  File "/usr/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)

Set TORCHDYNAMO_VERBOSE=1 for the internal stack trace (please do this especially if you're reporting a bug to PyTorch). For even more developer context, set TORCH_LOGS="+dynamo"

Minimal example:

import torch
torch.use_deterministic_algorithms(True)
pad = torch.nn.ReplicationPad1d(2).to('cuda:0')
a = torch.compile(pad, fullgraph=True)
a(torch.zeros(3, 3, device='cuda:0'))

I did some debugging - the issue lies here:
Probably we need to add torch.compiler.is_compiling check?

Versions

Collecting environment information...
PyTorch version: 2.9.1+cu128
Is debug build: False
CUDA used to build PyTorch: 12.8
ROCM used to build PyTorch: N/A

OS: Ubuntu 24.04.1 LTS (x86_64)
GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.39

Python version: 3.12.3 (main, Nov 6 2025, 13:44:16) [GCC 13.3.0] (64-bit runtime)
Python platform: Linux-5.15.0-161-generic-x86_64-with-glibc2.39
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to:
GPU models and configuration: GPU 0: NVIDIA H100 80GB HBM3
Nvidia driver version: 550.163.01
cuDNN version: Could not collect
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
Caching allocator config: N/A

CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 48 bits physical, 57 bits virtual
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Vendor ID: GenuineIntel
Model name: Intel(R) Xeon(R) Platinum 8468
CPU family: 6
Model: 143
Thread(s) per core: 2
Core(s) per socket: 8
Socket(s): 1
Stepping: 8
BogoMIPS: 4200.00
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq dtes64 ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves avx_vnni avx512_bf16 wbnoinvd arat avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b fsrm md_clear serialize tsxldtrk amx_bf16 avx512_fp16 amx_tile amx_int8 arch_capabilities
Hypervisor vendor: KVM
Virtualization type: full
L1d cache: 512 KiB (16 instances)
L1i cache: 512 KiB (16 instances)
L2 cache: 32 MiB (8 instances)
L3 cache: 16 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-15
Vulnerability Gather data sampling: Not affected
Vulnerability Indirect target selection: Mitigation; Aligned branch/return thunks
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Unknown: No mitigations
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; PBRSB-eIBRS SW sequence; BHI SW loop, KVM SW loop
Vulnerability Srbds: Not affected
Vulnerability Tsa: Not affected
Vulnerability Tsx async abort: Mitigation; TSX disabled
Vulnerability Vmscape: Not affected

Versions of relevant libraries:
[pip3] Could not collect
[conda] Could not collect

cc @chauhang @penguinwu @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @amjames @Lucaskabela @jataylo

Metadata

Metadata

Assignees

Labels

actionabledynamo-triage-dec2025small/mid-sized dynamo tasks that we would like to be completed in the near futuremodule: dynamooncall: pt2triagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions