GPU Support with PyTorch on Jetson Nano Using JetPack 4.6 and CUDA 10.2

Sanjana_Jain: <p>Hi,</p>
<p>I am using a Jetson Nano with the latest JetPack 4.6, which includes CUDA 10.2. It has come to my attention that PyTorch with GPU support for CUDA 10.2 is now outdated. Since the latest JetPack available is 4.6, it seems that I have no option left to utilize GPU with PyTorch on my Jetson Nano. I would greatly appreciate it if anyone could provide clarity or assistance regarding this matter.</p>

ptrblck: <aside class="quote no-group" data-username="Sanjana_Jain" data-post="1" data-topic="214264">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/sanjana_jain/48/74535_2.png" class="avatar"> Sanjana_Jain:</div>
<blockquote>
<p>Since the latest JetPack available is 4.6</p>
</blockquote>
</aside>
<p>The latest JetPack is 6.1 supporting CUDA 12.6.</p>

Doruk_Sonmez: <p>Hi <a class="mention" href="/u/ptrblck">@ptrblck</a>, I had the chance to test the latest compatible PyTorch version on the latest JetPack 6.1. However, as I and a couple of others described in this topic, this combination seems to have a problem. Could you please look into the error and let us know if there are recommendations?</p><aside class="quote quote-modified" data-post="5" data-topic="214062">
  <div class="title">
    <div class="quote-controls"></div>
    <img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/doruk_sonmez/48/74506_2.png" class="avatar">
    <a href="https://discuss.pytorch.org/t/runtimeerror-cuda-error-invalid-argument/214062/5">RuntimeError: CUDA error: invalid argument</a> 
  </div>
  <blockquote>
    Hi, I’m also having the same problem on NVIDIA Jetson AGX Orin 64GB while using PyTorch 2.5.0a0+872d972e41.nv24.08 and JetPack 6.0 (but inside a JetPack 6.1-based docker container). My workload is related to some LLM/VLM application but the error is pretty much the same: 
Process EmbeddingProcess-2:
Traceback (most recent call last):
  File "/usr/lib/python3.10/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/opt/nvidia/myapp/process_base.py", line 188, in run
    ite…
  </blockquote>
</aside>

<p>The same error is reproducible with the one line command described in this comment on GitHub:</p><aside class="onebox githubissue" data-onebox-src="https://github.com/pytorch/pytorch/issues/133976#issuecomment-2486403732">
  <header class="source">

      <a href="https://github.com/pytorch/pytorch/issues/133976#issuecomment-2486403732" target="_blank" rel="noopener nofollow ugc">github.com/pytorch/pytorch</a>
  </header>

  <article class="onebox-body">
    <div class="github-row">
  <div class="github-icon-container" title="Issue" data-github-private-repo="false">
	  <svg width="60" height="60" class="github-icon" viewBox="0 0 14 16" aria-hidden="true"><path fill-rule="evenodd" d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
  </div>

  <div class="github-info-container">
    <h4>
      <a href="https://github.com/pytorch/pytorch/issues/133976#issuecomment-2486403732" target="_blank" rel="noopener nofollow ugc">cuda sdpa meet RuntimeError: CUDA error: invalid configuration argument for some input shape</a>
    </h4>

    <div class="github-info">
      <div class="date">
        opened <span class="discourse-local-date" data-format="ll" data-date="2024-08-20" data-time="06:28:39" data-timezone="UTC">06:28AM - 20 Aug 24 UTC</span>
      </div>

        <div class="date">
          closed <span class="discourse-local-date" data-format="ll" data-date="2024-11-20" data-time="16:33:41" data-timezone="UTC">04:33PM - 20 Nov 24 UTC</span>
        </div>

      <div class="user">
        <a href="https://github.com/XiaobingSuper" target="_blank" rel="noopener nofollow ugc">
          <img alt="" src="https://avatars.githubusercontent.com/u/16217777?v=4" class="onebox-avatar-inline" width="20" height="20">
          XiaobingSuper
        </a>
      </div>
    </div>

    <div class="labels">
        <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">
          triaged
        </span>
    </div>
  </div>
</div>

  <div class="github-row">
    <p class="github-body-container">### 🐛 Describe the bug

For given qkv with shape (1, 65536, 8, 128), I meet ``<span class="show-more-container"><a href="" rel="noopener" class="show-more">…</a></span><span class="excerpt hidden">`RuntimeError: CUDA error: invalid configuration argument for some input shape```:
```Python
import pickle
import math
import torch
import torch.nn as nn
import torch.nn.functional as F

import time


def attention_pytorch_flash(qkv, dropout_p=0.0, causal=True):
    """
    Arguments:
        qkv: (batch_size, seqlen, 3, nheads, head_dim)
        dropout_p: float
    Output:
        output: (batch_size, seqlen, nheads, head_dim)
    """
    # batch_size, seqlen, _, nheads, d = qkv.shape
    q, k, v = qkv.unbind(dim=2)

    q =  q.contiguous()
    v = v.contiguous()
    k = k.contiguous()
    # with torch.backends.cuda.sdp_kernel(enable_flash=False, enable_math=False, enable_mem_efficient=True):
    output = F.scaled_dot_product_attention(q, k, v)
    return output.to(dtype=qkv.dtype)

qkv = torch.randn(1, 65536, 3, 8, 128).cuda().bfloat16()
for _ in range(100):
    output = attention_pytorch_flash(qkv)

torch.cuda.synchronize()
start = time.time()
for _ in range(100):
    output = attention_pytorch_flash(qkv)
torch.cuda.synchronize()
print("attention_pytorch_flash Time: ", (time.time()-start) / 100)
```

If I manually enable the math kernel, it works. If manually enable flash kernel, it reports similar error ```CUDA error (/opt/pytorch/pytorch/aten/src/ATen/native/transformers/cuda/flash_attn/fmha_fwd_launch_template.h:90): invalid configuration argument```.

If I change the seq_len ```65536``` to ```32768```, it works fine.




### Versions

Collecting environment information...
PyTorch version: 2.1.0a0+fe05266
Is debug build: False
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.5 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Clang version: Could not collect
CMake version: version 3.24.1
Libc version: glibc-2.31

Python version: 3.8.10 (default, Mar 13 2023, 10:26:41)  [GCC 9.4.0] (64-bit runtime)
Python platform: Linux-5.4.0-139-generic-x86_64-with-glibc2.29
Is CUDA available: True
CUDA runtime version: 12.1.66
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: NVIDIA A100-SXM4-80GB
GPU 1: NVIDIA A100-SXM4-80GB
GPU 2: NVIDIA A100-SXM4-80GB
GPU 3: NVIDIA A100-SXM4-80GB
GPU 4: NVIDIA A100-SXM4-80GB
GPU 5: NVIDIA A100-SXM4-80GB
GPU 6: NVIDIA A100-SXM4-80GB
GPU 7: NVIDIA A100-SXM4-80GB

Nvidia driver version: 470.199.02
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.9.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.9.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.9.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.9.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.9.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.9.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.9.0
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Little Endian
Address sizes:                   46 bits physical, 57 bits virtual
CPU(s):                          112
On-line CPU(s) list:             0-111
Thread(s) per core:              2
Core(s) per socket:              28
Socket(s):                       2
NUMA node(s):                    2
Vendor ID:                       GenuineIntel
CPU family:                      6
Model:                           106
Model name:                      Intel(R) Xeon(R) Platinum 8350C CPU @ 2.60GHz
Stepping:                        6
CPU MHz:                         2593.902
BogoMIPS:                        5187.80
Hypervisor vendor:               KVM
Virtualization type:             full
L1d cache:                       2.6 MiB
L1i cache:                       1.8 MiB
L2 cache:                        70 MiB
L3 cache:                        96 MiB
NUMA node0 CPU(s):               0-55
NUMA node1 CPU(s):               56-111
Vulnerability Itlb multihit:     Not affected
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Not affected
Vulnerability Meltdown:          Not affected
Vulnerability Mmio stale data:   Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown
Vulnerability Retbleed:          Not affected
Vulnerability Spec store bypass: Vulnerable
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Vulnerable, IBPB: disabled, STIBP: disabled, PBRSB-eIBRS: Vulnerable
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq monitor ssse3 fma cx16 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 arat avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid md_clear arch_capabilities

Versions of relevant libraries:
[pip3] numpy==1.22.2
[pip3] onnx==1.13.1
[pip3] pytorch-quantization==2.1.2
[pip3] torch==2.1.0a0+fe05266
[pip3] torch-tensorrt==1.4.0.dev0
[pip3] torchtext==0.13.0a0+fae8e8c
[pip3] torchvision==0.15.0a0
[pip3] triton==2.0.0
[conda] Could not collect

cc @jbschlosser @bhosmer @cpuhrsch @erichan1 @drisspg @mikaylagawarecki</span></p>
  </div>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>


ptrblck: <p>The linked posts unfortunately do not provide any information about the use case and also don’t provide code snippets to reproduce the issue, so it’s unclear which part of the code fails.<br>
From what I’ve read the issues are only raised if multiprocessing is used, so I assume other workloads are fine.</p>

Sanjana_Jain: <p>Hi,<br>
I meant the latest jetpack version for “JETSON NANO DEVELOPER KIT” is 4.6 series is what I noticed in the NVIDIA website.</p>