Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstalliTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Reducing GPU memory usage when VRAM is full starts with identifying what owns the memory. A full reading in nvidia-smi can represent live tensors, cached allocator blocks, another process, or a genuine workload peak. For PyTorch, compare allocated and reserved memory, remove lingering tensor references, then reduce the peak with smaller inputs, checkpointing, or supported lower-precision execution. Use allocator settings only when statistics show fragmentation, and treat torch.cuda.empty_cache() as a way to return unused cached blocks—not as a cure for tensors that are still live.
The exact remedy depends on whether you are training, running inference, compiling an engine, or rendering graphics. The commands and APIs below are PyTorch-specific where noted; they are not universal fixes for every GPU application.
What does “VRAM is full” actually mean?
A full VRAM report is a symptom, not a diagnosis. The memory may be occupied by your model’s weights, activations saved for backpropagation, gradients, optimizer state, temporary workspaces, or a different process. In PyTorch, the CUDA caching allocator can also retain unused blocks so that later allocations are faster. Those reserved blocks can still appear as used in nvidia-smi; the PyTorch FAQ notes that the values shown there “usually don’t reflect the true memory usage.”
Separate these situations before changing code:
- Another process owns the memory: stop or reconfigure that process, or choose a different GPU.
- Live tensors consume the memory: release references or reduce the workload.
- PyTorch has unused reserved blocks: clear the cache when appropriate, or investigate fragmentation.
- The workload genuinely peaks above capacity: reduce batch, sequence, image, or model-state requirements, or move part of the work to CPU/system memory.
Peak usage can occur during a particular operation—often backward propagation, an optimizer step, compilation, or a temporary workspace allocation—rather than when the model is first loaded.
Popular on Amazon
- 【90 Degree Full Function USB C Adapter】Supports the latest USB4 standard for up to 40Gbps of bandwidth, 8K video support, and up to 240W Fast charging; Support USB PD 3.1 Extended Power Range (EPR) including 140W, 180W and 240W. Your productivity is easily doubled. *Warm Tip: For the best fit, please make sure the USB-C port is fully exposed; thick or bulky cases may affect compatibility.
- 【Reliable Quality】Made from high-quality, scratch-resistant aluminum alloy, delicate metal frame. get excellent wear resistance and heat dissipation. Non-Slip Design for easier insertion and removal.
- 【Small and portable】Ultra thin size, ultra compact design, a petite physique that matches the minimalist design of your modern laptops. Coming with a slim figure that won't block the port next to the one it's plugged into.
- 【Compatibility】Widely work with most usb c, thunderbolt 4/3 devices. Compatibilit for ROG Ally, Steam Deck, Switch, MacBook Pro, Quest 3 VR headset, Surface Book 2, iPhone 18/17/16/15, Samsung Galaxy S23/S22/S21, Note 20/10, Google Pixel, ChromeBook, etc.
- 【Excellence Customer Support】If you experience any issues or cable failure, simply reach out to our dedicated customer service team. We provide a prompt response within 18 hours, providing you with the necessary technical support to resolve any concerns.
How do I identify which process is using the GPU?
First establish whether the failure belongs to your process. Run nvidia-smi while the application is idle and again immediately before the failure. Record the GPU index, total memory, used memory, and the process list. A desktop compositor, browser tab, another Python worker, or a stale job can consume capacity that your script expects to be free.
If a process is not yours, close it cleanly or stop the associated job using the operating system’s normal process controls. Do not kill an unknown production process merely because it appears in the list. In a multi-user server, ask the owner or administrator to release the allocation. If your program launches multiple workers, check whether each worker creates its own model copy; data-loader workers should not unexpectedly initialize CUDA.
For a PyTorch failure, print the device selected by the program and confirm it matches the GPU you inspected. A script can fail on GPU 0 while you are watching GPU 1. Also check for a second copy of the script left running after an earlier crash.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →How can I tell live tensor memory from PyTorch’s cache?
Compare memory allocated to live tensors with memory reserved by the caching allocator. Insert this diagnostic immediately before the operation that fails:
import torch
print("allocated:", torch.cuda.memory_allocated() / 1024**2, "MiB")
print("reserved:", torch.cuda.memory_reserved() / 1024**2, "MiB")
print(torch.cuda.memory_summary())
memory_allocated() is the memory occupied by live tensors. memory_reserved() is the total memory managed by PyTorch’s allocator, including blocks that may currently be unused. A large gap between reserved and allocated points toward cached blocks or fragmentation; a small gap means the tensors themselves are close to the device limit.
Use a memory snapshot when the difference is unclear or usage grows over time:
torch.cuda.memory._record_memory_history(enabled=True)
# run the section that eventually fails
snapshot = torch.cuda.memory._snapshot()
The snapshot and allocator statistics can show allocation sizes, inactive split blocks, and when memory changed. These interfaces are diagnostic and version-sensitive, so consult the CUDA semantics memory-management documentation for the version you run. Capture the history around the failure rather than assuming the largest number in nvidia-smi identifies the leak.
Free tools Windows power users keep installed
One-click scans. No signup required.
Also popular on Amazon
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
My model reports “cuda runtime error(2): out of memory”—what should I check?
In PyTorch, this message commonly means that the next allocation could not be satisfied. Check whether the request is a genuine peak or whether an earlier tensor, metric, or autograd graph is being kept alive accidentally.
Look for accumulated autograd history
If you add a differentiable loss tensor to a running total, each iteration can retain the graph needed to compute that loss. Track a scalar instead:
running_loss += loss.item()
When you need a tensor for logging or later processing but not for backpropagation, detach it explicitly:
logged_loss = loss.detach()
Do not retain outputs, hidden states, or intermediate tensors in a Python list unless you actually need their computation graphs. A list of tensors can keep every referenced graph alive even after the loop has moved on.
Recommended Free Tools
Check references that outlive their purpose
Local variables, object attributes, closures, callbacks, and debugging containers can all keep CUDA tensors reachable. Delete or overwrite references after the last use, and ensure a callback is not storing every batch’s output. Python garbage collection and CUDA deallocation happen only after references are gone; calling a cache-clearing function cannot free a tensor that your program still owns.
Inspect unusually large dimensions
A sequence length, image resolution, vocabulary projection, or linear layer with an accidental dimension can create a single allocation larger than the remaining VRAM. Print tensor shapes at the point where memory jumps. Verify that padding, batching, and preprocessing did not silently multiply the intended size.
How do I free GPU memory that my program no longer needs?
Release the references first, then consider clearing unused cached blocks:
Also popular on Amazon
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
del temporary_output
# Remove other references, such as list entries or object attributes.
torch.cuda.empty_cache()
torch.cuda.empty_cache() returns unused blocks held by PyTorch’s caching allocator so that other GPU applications can use them. It does not free memory occupied by live tensors and does not increase the memory available to PyTorch for those tensors. The official FAQ therefore does not present it as a general out-of-memory fix.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Calling it after every batch can force future allocations to request memory from the driver repeatedly, adding synchronization or allocation overhead. Use it at a real phase boundary—after deleting a completed model, between independent jobs, or before handing the GPU to another process—rather than as a substitute for fixing references or reducing a peak.
Which memory-saving lever matches the problem?
Choose a lever that targets the component shown by your diagnostics. The following map avoids applying a training remedy to an allocator problem or an inference remedy to a graphics application.
| Memory component | Typical indication | Targeted action | Main trade-off |
|---|---|---|---|
| Live tensors and outputs | memory_allocated() is near the device limit |
Delete references, detach logging values, reduce batch or dimensions | Less retained data or lower throughput |
| Saved activations | Training fails during backward or with long sequences | Activation checkpointing; smaller inputs | Extra forward computation |
| Gradients and optimizer state | Peak occurs during optimizer step | Reduce model/batch size; use a supported optimizer-memory strategy | Possible convergence or implementation changes |
| Cached allocator blocks | Reserved memory greatly exceeds allocated memory | Release references, then empty_cache() at phase boundaries |
Cache warm-up and allocation overhead |
| Fragmented blocks | OOM with substantial inactive split blocks | Investigate allocator statistics; tune max_split_size_mb as a last resort |
Pattern-dependent performance cost |
| Model weights during compilation or inference | Engine build or concurrent inference exceeds VRAM | CPU offload or weight streaming where supported | System RAM use, configuration complexity, or latency |
How can I reduce memory during training?
Training holds more than parameters. During a forward and backward pass, memory can include model weights, saved activations, gradients, optimizer state, and temporary allocations. A model that fits for inference can therefore fail during training. The PyTorch optimizer tutorial illustrates that Adam’s optimizer state is twice the parameter memory in its example; that is an example of the setup, not a universal formula for every optimizer or model.
Reduce the batch or input dimensions
Lower the batch size first when the failure scales with the number of samples. For sequence models, shorten the sequence or use a memory-conscious batching policy. For vision workloads, reduce image dimensions or crop before the model. These changes directly reduce activation and temporary-tensor sizes, but they may lower throughput or alter training dynamics. If you compensate with gradient accumulation, remember that accumulation can preserve or increase some memory requirements; measure the resulting peak instead of assuming it is cheaper.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Use activation checkpointing when activations dominate
Checkpointing discards selected forward activations and recomputes them during backward. PyTorch describes this as trading memory for compute. It is useful when saved activations, rather than weights or optimizer state, are the dominant component. The additional forward work increases step time, and checkpoint boundaries must be supported by the model’s operations. Validate gradients and numerical behavior after enabling it.
Consider supported lower-precision execution
Lower-precision values can reduce the storage required for weights, activations, and some temporary tensors. NVIDIA’s mixed-precision guide distinguishes FP16’s 16 bits per value from FP32’s 32 bits per value. That does not guarantee that total training memory will be cut in half: gradients, optimizer state, master weights, workspace choices, and framework policies may remain at other precisions.
Also popular on Amazon
- Portable and powerful USB-C HUB: BENFEI USB Type-C HUB, with super-soft and knot-free silicone woven design cable, meets most mobile office needs. Compact, lightweight, stylish, and powerful portable USB C Hub equipped with 1 x HDMI port, 1 x 100W charging, and 3 x USB ports. 18-month warranty, 24-hour response, to ensure you feel at ease when using our product.
- Design centered on comfort and reliability: Thanks to BENFEI's end-to-end in-house cable production capability, in-house PCBA and assembly capability, using the industry's most advanced silicone woven design and process, 20cm cable in length, no knots, super-soft, the HUB is easy to use in all scenarios: laptop, tablet, stand etc. Super-soft, 25000+ life cycles, to meet your daily carrying and office needs.
- 100W Charging: Support up to 90W USB C pass-through charging via Type-C port to keep your laptop powered. 10W is reserved for other interface operations. No data and video function on the Type-C port.
- 4K HDMI Display: The HDMI port supports media display at resolutions up to 4K 30Hz, keeping every incredible moment detailed and ultra vivid. Please note that the C port of the Host device needs to support video output.
- Transfer Files in Seconds: Transfer files and from your laptop at speeds up to 10 Gbps with USB A 3.2 port. Extra 2 USB A 2.0 ports are perfectly for your keyboards and mouse.
Use the precision mode supported by your GPU, framework, and model, and validate loss scaling, convergence, overflow behavior, and checkpoint compatibility. A numerically unstable model can fail or produce unusable results even when it fits in VRAM. Do not claim a fixed percentage saving or speedup for an unknown workload; the actual result depends on tensor shapes and implementation.
Review optimizer memory as a separate budget
If the peak is during or immediately before the optimizer step, activations may not be the main issue. Reduce the model or batch size, select an optimizer configuration supported by your project, or evaluate an advanced memory-saving implementation. The PyTorch tutorial describes fusing the optimizer step into the backward pass so gradients and optimizer intermediates can be released earlier. It also limits the benefit when gradient accumulation is required or gradients are not a significant share of memory. Treat this as a model-dependent optimization, not a default switch.
Can allocator settings fix fragmentation?
Only use allocator tuning after statistics show an allocator problem. PyTorch documents max_split_size_mb as a last-resort option for workloads that run out of memory while reporting many inactive split blocks. It can keep large blocks from being split into pieces, but its performance effect depends on the allocation pattern.
Set the option before starting the process, for example through the environment variable documented by PyTorch:
PYTORCH_ALLOC_CONF=max_split_size_mb:128 python train.py
The value above is only an example of syntax, not a recommended universal setting. Try a value based on the block sizes visible in your statistics, compare peak memory and runtime, and remove the setting if it does not help. Copying a value from an unrelated machine can make allocations slower or leave usable memory stranded in unsuitable block sizes. Consult the current allocator documentation for additional options and version-specific behavior.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.What options exist for inference and compilation?
Inference usually avoids saved training activations, but large weights, concurrent models, dynamic shapes, and compilation workspaces can still exceed VRAM. Specialized workflows expose controls that are not general PyTorch or game settings.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesTorch-TensorRT compilation
The Torch-TensorRT resource-management guide documents offload_module_to_cpu=True for moving weights to CPU memory while an engine is built. This can reduce the peak GPU allocation during compilation, but it requires enabling the feature in the Torch-TensorRT configuration and consumes system RAM.
Also popular on Amazon
- 【Read before You Buy】 Note: This adapter is USB 2.0 version and cannot transmit HDM, VGA, or other video signals. Nevertheless, they are fully capable of charging devices,duplicating files, and can be seamlessly integrated with USB-C earphones, wireless network adapters, and SD card adapters.
- 【Easy to Use and Safe】Thanks to modern manufacturing techniques, we've made these adapters sufficiently compact so that they can remain inserted in your device without noticeable protrusion or inconvenience. This means you don't have to constantly plug and unplug them, reducing the likelihood of wear and misalignment, and making them more convenient to carry around.
- 【Reliable Quality】Engineered for enhanced durability, durable aluminum alloy shell material,get excellent wear resistance and heat dissipation,the male USB C and female USB connectors & the male USB and female USB C connectors are designed to be plugged and unplugged up to 20000 times. Provides data transfer, device charging, memory space expansion, and additional computer peripherals.
- 【Think more for you】Do you need to connect a USB-C-enabled device to an odd device that only has USB-A ports? Then these USB-A male to USB-C female adapters are made for you.Simply insert the adapter into the USB-A port on the device, and you can instantly connect your USB-C device to the device that originally didn't have the correct connection port.
- 【Trusted xiwxi Quality and Service】As a responsible brand seller, you will receive xiwxi's 12-month Quality assurance and lifetime friendly customer service, you're not just buying a product,you're investing in peace of mind with all-round quality and exceptional customer service.
The same guide documents inference-time weight streaming, which loads weights from CPU memory on demand, and dynamic resource allocation for scenarios where multiple compiled models run concurrently. These features can reduce peak GPU use, but weight transfers may increase per-call latency and require additional configuration. They are appropriate only when your deployment uses the corresponding Torch-TensorRT workflow.
Unified-memory hardware caveat
On unified-memory systems such as the Jetson or DGX Spark configurations described in the guide, CPU and GPU allocations share one physical pool. Moving a weight from a GPU-visible allocation to “CPU” memory therefore does not necessarily free physical memory; it changes how the software accounts for or accesses that shared pool. Check the hardware-specific documentation before assuming that offload creates capacity.
What if the full VRAM condition comes from a game or another framework?
The PyTorch APIs in this guide do not control a game engine, a video editor, or another machine-learning framework. Use that application’s own memory overlay and settings to identify textures, render targets, shader caches, model assets, or background processes. Lower texture or render resolution, close competing GPU applications, and restart the affected process when its allocator does not return memory correctly.
The general reasoning still applies: determine ownership, distinguish live allocations from cached or reserved memory, reduce the largest peak contributor, and change one variable at a time. Do not set PYTORCH_ALLOC_CONF or call torch.cuda.empty_cache() expecting them to alter an unrelated application.
How do I prevent VRAM from filling again?
- Log the peak: record allocated and reserved memory before and after forward, backward, optimizer, compilation, and inference calls.
- Keep metrics scalar: use
.item()or detached tensors for history and logging. - Bound retained data: cap prediction lists, clear per-batch caches, and remove object attributes that are no longer needed.
- Set a realistic workload: choose batch, sequence, image, and concurrency limits that leave room for temporary allocations.
- Separate phases: release a completed model before loading the next one, then clear unused cached blocks if another process needs the GPU.
- Monitor all processes: include background workers and scheduled jobs in capacity planning.
- Document precision and allocator choices: record the framework version, GPU, precision mode, and any allocator setting so a deployment can be reproduced.
A practical recovery checklist
When an OOM stops a job, follow this order:
- Save the error and the operation that failed; the failing phase identifies likely memory components.
- Run
nvidia-smiand identify every process on the device. - In PyTorch, compare
memory_allocated()andmemory_reserved(), then inspect a memory summary or snapshot. - Remove retained losses, outputs, hidden states, and other references; use scalar or detached values for logging.
- Retry with a smaller batch, sequence, image, or concurrency setting.
- If activations dominate training, enable supported checkpointing and accept the extra compute.
- If precision is the issue, use a supported lower-precision mode and validate numerical results.
- Only when inactive split blocks indicate fragmentation, test
max_split_size_mbbefore the process starts. - For supported Torch-TensorRT deployments, evaluate CPU offload or weight streaming and measure the latency/system-RAM trade-off.
This sequence prevents a common mistake: treating every “full” reading as a cache that can be emptied. If live tensors, optimizer state, or saved activations exceed physical capacity, the durable fix is to lower the peak or distribute the workload—not to repeatedly flush unused blocks.
How we chose these remedies
The recommendations are organized by the memory component they affect, the workload context (training, inference, or compilation), and their trade-offs in compute, latency, numerical behavior, system RAM, and framework specificity. The technical details come from the cited PyTorch, NVIDIA, and Torch-TensorRT documentation rather than from a cross-workload benchmark.
Frequently Asked Questions
Will FP16 always cut my GPU memory use in half?
No. FP16 stores an individual value in 16 bits instead of FP32’s 32 bits, but a training job may keep optimizer state, gradients, master weights, or workspaces at other precisions. The resulting total depends on the model and framework implementation, so validate both memory and numerical behavior.
Why does VRAM still look occupied after my Python function returns?
A tensor may still be referenced by a list, object attribute, callback, or retained autograd graph. If references are gone, PyTorch may still hold unused blocks in its caching allocator; those blocks can appear in system-level monitoring until they are released or reused.
Is it safe to call torch.cuda.empty_cache() after every batch?
It does not free live tensors and can add allocation overhead by discarding reusable blocks repeatedly. It is generally more appropriate at phase boundaries or before another process needs the GPU, after you have removed references to objects you no longer need.
Does moving weights to CPU always create more physical memory on a Jetson device?
Not on unified-memory systems where CPU and GPU allocations share the same physical pool. In those configurations, documented offload features may change access and accounting but cannot manufacture additional physical capacity.

