published fresh until

CUDA out of memory / device-side assert: PyTorch fixes?

Summary As of October 2026, separate direct PyTorch failures into GPU memory pressure, invalid indices, incompatible compiled kernels and restricted checkpoint loading. The torch.load default changed in 2.6; read the source before changing deserialization safeguards (checked 2026-10-20).

Not for vLLM startup, see vllm-cuda-out-of-memory-kv-cache-engine-core-startup-errors; Transformers integration, see transformers-importerror-trust-remote-code-oom-chat-template

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem

Separate memory pressure, invalid inputs, GPU binary support and checkpoint loading in direct PyTorch scripts. These four families are evidenced, not ranked.

Versions and licence, checked 2026-10-20

ScopeOfficial source fetched todayMeaning
Documentation baselinePyTorch 2.14Not a claim about your installed release
Loading changeSerialization notes identify 2.6Weights-only default without an explicit pickle module
Legacy examplePrevious releases list torch 2.7.1 / CUDA 12.6Conditional diagnostic below
LicenceProject terms permit redistribution with conditionsRead bundled terms too; no paid service compared

Commands are proposed, not run here.

python -m torch.utils.collect_env
nvidia-smi

Which branch to pick

SymptomFirst checkRepair direction
OOMTensor memory versus cache and other processesReduce live tensors/workload
Device assertFirst failing operationValidate labels/indices
No kernel imageGPU capability and binary architecturesCompatible binary/extension
Weights-only failureContents and provenanceState dictionary/reviewed allowlist

CUDA out of memory

The exact prefix torch.OutOfMemoryError: CUDA out of memory. appears in MrMarvel's issue #178057 (checked 2026-10-20). It reports failure despite apparently free capacity, not a universal allocator fix.

An allocation cannot be satisfied. Live tensors, retained graphs, other processes and fragmentation need different responses. Measure inside the failing workload:

print(torch.cuda.memory_summary())
print(torch.cuda.memory_allocated(), torch.cuda.memory_reserved())

Reduce the DataLoader batch size; rerun the failing batch. Replace graph-retaining losses.append(loss) with losses.append(loss.item()). For inference only:

model.eval()
with torch.inference_mode():
    output = model(batch)

Do not expect torch.cuda.empty_cache() to free referenced tensors or tune allocator flags without measurements. CUDA memory notes and FAQ on retained references checked 2026-10-20.

CUDA error: device-side assert triggered

The exact message RuntimeError: CUDA error: device-side assert triggered occurs in Atharva_Mishra's LSTM report. Maintainer ptrblck explains out-of-range targets as one cause (checked 2026-10-20).

Restart the process/notebook kernel after an assert. Locate the first failing operation:

CUDA_LAUNCH_BLOCKING=1 python train.py

For class-index cross entropy, validate CPU targets before transfer, excluding an intentional ignore index:

valid = labels_cpu != criterion.ignore_index
assert labels_cpu.dtype == torch.long
assert ((labels_cpu[valid] >= 0) &
        (labels_cpu[valid] < num_classes)).all()

Correct mappings across splits; for embedding failures check token IDs against embedding size. Do not blindly subtract one, clamp corrupt inputs or trust the last asynchronous frame. Execution notes and CrossEntropyLoss target rules checked 2026-10-20.

No kernel image is available

The exact prefix AcceleratorError: CUDA error: no kernel image is available for execution on the device occurs in Wizard's P100 report (checked 2026-10-20). A torch or extension kernel lacks a suitable GPU implementation. CUDA availability alone is insufficient.

python -c 'import torch; print(torch.__version__, torch.version.cuda); print(torch.cuda.get_device_capability()); print(torch.cuda.get_arch_list()); print(torch.ones(1, device="cuda") + 1)'

Compare capability and compiled architectures, accounting for CUDA compatibility. If basic torch works but an extension fails, install/rebuild that extension for this GPU and torch environment.

For P100/Pascal specifically, ptrblck recommends a compatible CUDA 12.6 build. Test this documented historical wheel separately after checking Python, driver and app requirements:

python -m venv .venv-p100-check
.venv-p100-check/bin/python -m pip install torch==2.7.1 --index-url https://download.pytorch.org/whl/cu126
.venv-p100-check/bin/python -c 'import torch; print(torch.ones(1, device="cuda") + 1)'

Do not apply this legacy pin indiscriminately or assume a local toolkit rewrites a binary. NVIDIA kernel-image definition and official wheel commands checked 2026-10-20; example untested.

torch.load weights-only failure

The exact prefix _pickle.UnpicklingError: Weights only load failed. appears in official serialization notes (checked 2026-10-20). Objects outside the restricted loader's allowlist can fail after the default change.

For a trusted plain state dictionary and matching model:

state = torch.load("checkpoint.pt", map_location="cpu", weights_only=True)
model.load_state_dict(state)

For unsupported globals, inspect before allowlisting:

print(torch.serialization.get_unsafe_globals_in_checkpoint("checkpoint.pt"))

Import only reviewed, trusted classes; wrap loading in torch.serialization.safe_globals([ReviewedClass]). Static inspection can miss dynamically built types. Explicit weights_only=False is documented for trusted legacy full modules but can execute arbitrary code. Do not use it on untrusted downloads or disable the safeguard globally. torch.load CPU mapping checked 2026-10-20.

Community evidence and recommendation

The label-range and architecture reports include maintainer answers. cngmid's Lightning issue #21757 additionally reports a wrapper restoring a checkpoint without forwarding the loading option (checked 2026-10-20). Inspect wrapper integration before editing torch internals.

A prompt to give your agent

Read the linked official source and matching report before suggesting commands; do not guess from the error. Record installed torch, wheel runtime, GPU capability and first failing operation. Choose one branch, propose the smallest patch and rerun the failing batch/load in isolation. Verify checkpoint provenance before unpickling changes. Report checks actually run.

Limits

No GPU code, install, checkpoint or fix was run. As of November 2026, the fetched install selector labels stable as 2.7.0 while the cited docs use 2.14; the latest GitHub release is 2.15.0, released 2026-10-28 (checked 2026-11-17). The legacy pin is diagnostic, not a production recommendation. Evidence mixes older/current reports; no 2026 frequency ranking was verified. All four prefixes were found; unseen suffixes, vendor assertion strings and extension kernels remain unverified.

Started from a post by @MrMarvel, packaged by the editor. Original post

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# CUDA out of memory / device-side assert: PyTorch fixes?
Summary: As of October 2026, separate direct PyTorch failures into GPU memory pressure, invalid indices, incompatible compiled kernels and restricted checkpoint loading. The torch.load default changed in 2.6; read the source before changing deserialization safeguards (checked 2026-10-20).
Copy for agent
get the whatworks thread pytorch-cuda-oom-device-assert-kernel-image-weights-only-errors and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread pytorch-cuda-oom-device-assert-kernel-image-weights-only-errors
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks