Skip to content

Operator task guide

How to debug CUDA error 700, illegal memory access, and device-side asserts

CUDA error 700 (cudaErrorIllegalAddress: an illegal memory access was encountered) and device-side assert triggered are asynchronous kernel faults: the Python traceback almost always points to a later synchronization line rather than the kernel that broke. Always re-run a minimal reproducer with CUDA_LAUNCH_BLOCKING=1 first.

For device-side asserts, check embedding token IDs and classification target labels (such as negative labels other than ignore_index -100, or token IDs >= vocab_size). For illegal memory access in custom or attention kernels, run compute-sanitizer --tool memcheck and inspect host dmesg for concurrent Xid 31/48/79 events.

Reviewed . Reference guidance is not a diagnosis of your workload.

Step-by-step method

  1. 1

    Make kernel launches synchronous to find the true failing Python line

    Set CUDA_LAUNCH_BLOCKING=1 (and TORCH_USE_CUDA_DSA=1 if your PyTorch build supports device-side assertions) so the traceback stops at the exact offending op.

    CUDA_LAUNCH_BLOCKING=1 TORCH_USE_CUDA_DSA=1 python3 train.py
  2. 2

    Check token IDs and loss labels for index-out-of-bounds asserts

    Device-side asserts in Embedding or CrossEntropyLoss happen when input_ids >= vocab_size, input_ids < 0, or labels sit outside [0, num_classes - 1] without matching ignore_index.

    python3 -c "# Validate batch bounds in your dataloader check:
    # assert input_ids.min() >= 0 and input_ids.max() < model.config.vocab_size"
  3. 3

    Run NVIDIA Compute Sanitizer memcheck on custom CUDA/Triton kernels

    When CUDA_LAUNCH_BLOCKING=1 still points to an illegal memory access inside a fused attention, LoRA, or C++ extension kernel, run compute-sanitizer --tool memcheck on a 1-step minimal reproducer.

    compute-sanitizer --tool memcheck --show-backtrace=device python3 minimal_repro.py
  4. 4

    Rule out hardware ECC or PCIe faults and tensor device mismatches

    Check dmesg for simultaneous Xid 31, 48, 79, or 95 errors. For Expected all tensors to be on the same device errors, register persistent buffers with register_buffer() and avoid mixing CPU index tensors with CUDA tensors unintentionally.

    dmesg -T | grep -iE 'NVRM: Xid|ECC'

Kernel fault classification

Signals, meanings and actions for how to debug cuda error 700, illegal memory access, and device-side asserts.
SignalWhat it meansNext action
device-side assert inside Embedding or NLLLoss/CrossEntropyOut-of-range token ID or target class label.Assert input_ids < vocab_size and verify resize_token_embeddings matches tokenizer.
CUDA error 700 / illegal memory access in custom or attention kernelOut-of-bounds pointer, bad stride, or corrupted workspace.Run compute-sanitizer --tool memcheck and check FlashAttention/Triton versions.
Expected all tensors to be on the same deviceOperand, mask, or restored optimizer tensor remains on CPU or wrong rank.Use register_buffer() and move batch/optimizer tensors to local rank device.
Illegal memory access coincides with Xid 48/79/94/95 in dmesgDevice memory or link hardware error poisoned GPU state.Preserve UUID/dmesg and drain GPU for hardware diagnostics.

Evidence checklist

  • Traceback captured with CUDA_LAUNCH_BLOCKING=1
  • compute-sanitizer --tool memcheck output for custom/Triton kernels
  • Tokenizer vocab_size vs model embedding size and label min/max
  • Host dmesg Xid lines around the failure timestamp
  • PyTorch, CUDA, FlashAttention, and Triton package versions

Common mistakes

Debugging the async traceback without CUDA_LAUNCH_BLOCKING=1

Without synchronous execution, the traceback points at whichever collective or .item() synced next.

Resizing tokenizer special tokens without calling model.resize_token_embeddings()

Adding pad/chat tokens bumps tokenizer IDs past embedding table rows and triggers immediate device-side asserts.

Ignoring Xids when error 700 happens intermittently across runs

Hardware ECC or PCIe faults can surface as illegal address errors; always verify dmesg.

Frequently asked questions

What is CUDA error 700?

Error code 700 in the CUDA runtime/driver enum is cudaErrorIllegalAddress (an illegal memory access was encountered), meaning a GPU kernel read or wrote invalid memory and poisoned the CUDA context.

Why does device-side assert triggered say index out of bounds?

PyTorch embedding layers and loss functions assert inside CUDA kernels that indices fall within valid vocabulary or class bounds. Adding chat/special tokens without resizing model embeddings is a frequent cause.

Can I recover from CUDA error 700 with try/except in Python?

No. Once an illegal memory access occurs, the CUDA context is corrupted until the OS process exits and restarts.

How do I fix Expected all tensors to be on the same device?

Inspect operands at the failing line, register non-parameter tensors with self.register_buffer(), and confirm multi-GPU ranks move inputs to torch.device("cuda", local_rank).

Live diagnosis, no signup

Upload your GPU log. Find what happened first.

Get the likely cause, supporting evidence, and next safe steps with the same cloud reasoning used by paid plans. A crash the engine recognizes is answered in seconds, then checked by an independent AI review that updates this page when it finishes. A crash it does not recognize waits for the AI's own answer, which can take a few minutes. No account, card, or installation. Logs are masked at Denpex API ingress and are not saved to account history.

Before uploading, review cloud data handling and local options.

training_logs.txt
No log to hand? Try one:

Upload your log file. Large files are processed in your browser. Only selected evidence is submitted when you run diagnosis.

3 free cloud diagnoses per day

Try Denpex for 30 days. FREE.

No credit card. No automatic subscription. See whether Denpex helps with an incident you already understand.

Start your free 30-day Team evaluation

Up to 50 diagnoses a day for 30 days. Verify your work email to activate an eligible company evaluation, then replay a resolved incident and compare the evidence and next steps with your team's confirmed cause.

Use your company email, for example alex@yourcompany.com.

Who qualifies?

Company email domains activate the free 30-day Team evaluation (up to 50 diagnoses a day) after an email and domain check, whatever mail provider you use. If we cannot verify your domain automatically, support reviews it: write to support@denpex.com. Free local diagnosis in the editor extension needs no account.

Using a personal email (Gmail, Outlook, Naver, QQ) or solo cluster? Create a free $0 account (no work email required) to save 7-day history and unlock AI fallback, or send a cluster crash log for a live walkthrough.

Apply the method to your incident

Use the three free diagnoses to review your error and relevant evidence. Keep reference guidance separate from the cause and recovery status of your own workload.

Diagnose your incident