LoRA Training Crashes with CUDA Out of Memory Mid-Run? Gradient Checkpointing, LoRA Rank & Optimizer-State Diagnosis Guide

2026-11-23 | GPU Repair | 36 minutes | HK GPU Fix Editorial Team

LoRA Training Crashes with CUDA Out of Memory Mid-Run? Gradient Checkpointing, LoRA Rank & Optimizer-State Diagnosis Guide

Key takeaway

When LoRA training crashes with CUDA out of memory halfway through a run, the cause is usually one memory pool, not the whole model: activations, the training phase, or the per-step batch size. Three controlled comparisons — gradient checkpointing, crash timing, and gradient accumulation — identify which pool overflowed first.

Introduction

Training starts. The first steps run, the loss numbers appear, and the progress bar moves. Then, halfway through a run that was working a moment ago, the process stops with `CUDA out of memory`. Nothing about the model changed. The model loaded, inference runs on the same model without any trouble, and the first steps of training completed. The only thing that changed is that training reached a point where the memory it needed passed the memory the card had.

That shape — training that starts, runs for a while, and then crashes — has a specific cause, and it is not "the model is too big". If the model were too big, it would fail while loading, before the first step. If inference also failed, the fault would be in the allocator or the serving budget. What fails here is specific to training: while training runs, the graphics card holds four different things at once, and one of them grows until the total passes the limit. The fix depends entirely on which one grew, because each pool has a different switch.

The four pools are the weights of the frozen base model, the gradients of the adapter, the optimiser state for the trainable parameters, and the activations — the intermediate results of the forward pass that must be kept for the backward pass. LoRA shrinks only two of those pools. It does nothing at all to the activations, which is the pool that most often overflows. A guide that treats "training out of memory" as one problem, with one fix, will keep missing the cause.

This guide explains how the four pools work, how to prove which one overflowed, and how to avoid the mistakes that make the diagnosis look confusing. It is a diagnostic guide for one narrow shape: LoRA fine-tuning that starts, runs for some steps, and then crashes with `CUDA out of memory`. If the model fails while loading, if inference also crashes, or if the model runs on the CPU instead of the GPU, different articles apply, and the boundary section near the end says which ones.

Symptom definition: what counts as this problem

This article covers one narrow shape. All three of the following must be true; if any one is missing, the problem belongs somewhere else.

First, LoRA fine-tuning starts and runs for the first few steps, and only then crashes with `CUDA out of memory`. Training begins, loss numbers appear, and progress is made — it is not a crash at the very start. A crash while the model is loading, before any training step, follows the planning route in article #179 or the allocator route in article #552.

Second, the same model runs inference without crashing. Inference, generation, and loading the model all work normally; only training crashes. If inference crashes too, the route is article #552 (the PyTorch cache allocator) or article #553 (the vLLM budget and preemption route).

Third, the crash follows the training settings, not the model size. Change one training switch — gradient checkpointing, rank, optimiser, or micro-batch — and the crash changes; leave the switches alone and even a small model crashes in the same way. The model itself is not too big; the training settings decide which pool overflows.

These three shapes need to be kept apart because each one is measured differently. An inference crash with `CUDA out of memory` is the PyTorch cache-allocator route in article #552 — allocated against reserved-but-unallocated memory, fragmentation, and the `expandable_segments` switch — or the vLLM KV Cache budget route in article #553. An Ollama model running on the CPU is the `num_gpu` layer-count route in article #556. A model that cannot fit at all, or the question of which card to buy before purchase, is the planning arithmetic in article #179. Training data loading slowly, with the GPU waiting for data, is the data-pipeline route in article #562. This article is about the memory pools of the training process itself: while training runs, the GPU holds four things at once, and the question is which one overflowed first, and which switch releases it.

Five layers of mechanism

While training runs, the GPU holds four things at once. Four external sources agree on this four-way split, and article #156 states the same split as a principle — while adding, in its own words, that it covers the AI part only as a principle and does not promise that a particular model will run on a particular card. This article turns that principle into five layers of suspicion and three decisive tests.

Layer one: the activations layer — gradient checkpointing on or off. This is a main subject of this article. Activations are the intermediate results of the forward pass, kept so the backward pass can compute gradients. This pool exists only in training; inference has no backward pass and no such pool. It grows with the number of layers, the micro-batch size, and the sequence length, and it has nothing to do with the LoRA rank. Gradient checkpointing targets exactly this pool: instead of storing every intermediate result, it discards them during the forward pass and recomputes them during the backward pass, trading speed for memory — about a 50–70% reduction in activations, at a cost of about 20–30% slower training. The finetune-calc formula estimate for QLoRA on an 8B model, with batch 4 and sequence length 2048, puts the difference in plain numbers: checkpointing on, 5.4 GiB; checkpointing off, 12.0 GiB — more than double. The evidence for this layer is test T1. Across the whole article library, "gradient checkpoint" and the Chinese term for gradient checkpointing appear zero times in either language, and article #552 contains no mention of checkpointing at all.

Layer two: the phase layer — whether the crash happens in a training step or in validation sampling. This is a main subject of this article. A training step and a validation sampling pass are two different phases with different memory peaks. During validation, the AdamW optimiser state and the VAE decoder have to be on the GPU at the same time, and the LTX trainer documentation states that an out-of-memory error only during validation is usually caused by exactly that — the AdamW state and the VAE decoder cannot coexist on the GPU. The fix for that shape is to offload the optimiser state during validation (`offload_optimizer_during_validation: true`) or to shrink the validation resolution or frame count. The way to separate this layer is test T2. No article in the library teaches using "which phase crashed" as a decisive test; articles #552 and #553 are both about inference or loading phases, and the training phase is not in either of them.

Layer three: the gradient-accumulation layer — the micro-batch size against the effective batch. This is a main subject of this article. The micro-batch size decides the activation peak of each step. The effective batch — micro-batch multiplied by the number of gradient accumulation steps — decides the batch size the learning-rate schedule expects. A micro-batch of 1 with 4 accumulation steps has an effective batch of 4, exactly the same as a micro-batch of 4 with 1 accumulation step, but each step holds the activations of only one sample. The way to separate this layer is test T3. Article #552 test T5 is a "batch and model shrink" test: it shrinks the micro-batch to 1 and compensates with gradient accumulation, or drops the model down one quantisation level — the two offered as alternatives, with no explicit fixed-effective-batch protocol. T3's variable is the micro-batch size while the effective batch stays unchanged, and its outcome is "out of memory or completes, at the same effective batch" — a different variable and a different measured result.

Layer four: the adapter-parameter layer — the LoRA rank. This is a support test, not one of the three main tests, and the reason is honest arithmetic. The rank decides how many trainable parameters the adapter has, and therefore how large the gradient pool and the optimiser-state pool are. The finetune-calc formula estimate for an 8B model puts the scale in plain numbers: rank 8 has 14.7 million trainable parameters and 16.5 GiB total memory; rank 64 has 117.4 million trainable parameters and 17.5 GiB total memory. An eightfold increase in rank adds about 1 GiB, because the frozen base model is the large part of the total. So the rank ladder only decides the outcome at the edge — when the run is about 1 GiB short. Away from the edge, rank 8 and rank 64 crash together or complete together, and test T4 cannot separate the layer. This article lists T4 as a support test for exactly that reason, and it also states the cost of the other direction: a smaller rank learns less new knowledge, so shrinking the rank is not free.

Layer five: the optimiser-state layer — the 8-bit optimiser switch. This is a support test, not one of the three main tests, and again the reason is honest arithmetic. Adam and AdamW store two values per trainable parameter — momentum and variance — at 8 bytes per parameter in fp32, and 2 bytes per parameter with an 8-bit Adam optimiser from bitsandbytes, cutting optimiser-state memory by about 75%. For full fine-tuning the pool is the largest one of all: on an 8B model, Adam costs 121.1 GiB against 76.2 GiB for 8-bit Adam, a saving of about 45 GiB. For LoRA, the optimiser holds only the adapter, a few hundred megabytes, and the finetune-calc guide says so directly: for LoRA and QLoRA, this lever is irrelevant there. The Motion-LoRA example puts a number on it: at rank 16, standard AdamW holds about 240 MB of optimiser state and AdamW 8-bit holds about 60 MB, saving about 180 MB. So test T5 is only decisive in two situations: a high rank, where the adapter has many parameters, or a validation-phase crash, where the AdamW state and the VAE decoder cannot coexist. This article lists T5 as a support test for exactly that reason.

The mechanism leads to one key distinction: LoRA saves only the gradient pool and the optimiser-state pool, and it does nothing at all to the activations pool. The Medium guide on training out-of-memory errors states it directly: LoRA and quantisation shrink the parts that scale with parameters, they do nothing for activations, and if a run is still out of memory after switching to LoRA, the batch size or sequence length is probably the real problem. In other words, a LoRA run crashing does not mean LoRA failed. It means the next question is which pool overflowed — and there are four pools, with four different switches.

The four pools, in one table

Memory poolWhat it holdsWhat decides its sizeWhich switch releases it
Weights (frozen base)The base model, frozen during LoRA fine-tuningModel size and precision; unchanged through trainingNone in this article — loading route, #179 / #552
Gradients (adapter only)Gradients for the adapter parameters onlyLoRA rankRank ladder (T4, support test)
Optimiser stateAdam / AdamW momentum and variance per trainable parameterRank, and optimiser precision (8 bytes fp32, 2 bytes 8-bit)8-bit optimiser (T5, support test)
ActivationsIntermediate results kept for the backward passLayers × micro-batch × sequence length; nothing to do with rankGradient checkpointing (T1); gradient accumulation (T3)

One more relationship must be stated plainly, because the same error text appears in two articles. LoRA training runs on PyTorch, under the same cache allocator that article #552 covers, so the allocator layer sits underneath the four pools. Article #552's `expandable_segments` switch is an allocator switch: it changes how the allocator handles fragmentation, and it does not make activations smaller or optimiser state smaller. This article is not a rewrite of #552. It is the training-pool diagnosis that #552's own boundary hands over, in its words, to each framework's own tools — and the training switches are those tools here. The allocator switch is not useless for training out-of-memory errors; it is simply not the main cause, and this article keeps the boundary between the allocator layer and the training-pool layer intact.

Why the numbers in this article are estimates, not promises

The figures quoted in this article are formula estimates and worked examples from the sources, not measurements from a local machine. The checkpointing figures — 5.4 GiB against 12.0 GiB — are finetune-calc's formula estimate for QLoRA on a Llama 3.1 8B model at batch 4 and sequence length 2048. The rank figures — 16.5 GiB at rank 8 against 17.5 GiB at rank 64 — are the same source's formula estimate for the same 8B model. The optimiser figures — about 240 MB against about 60 MB at rank 16 — come from the Motion-LoRA example, a 1.6B model. The 20–30% slowdown for checkpointing is the range both finetune-calc and Motion-LoRA give, from opposite directions: one says switching checkpointing off saves roughly a quarter to a third of the compute, the other says switching it on is 20–30% slower. Tests T1, T4, and T5 in this article use only the direction of the change, never a fixed number, and readers should take their own framework version's behaviour as authoritative. The framework switch names also differ between frameworks — TRL, PEFT, kohya, diffusers, and the LTX trainer do not all spell the same switch the same way — so this article describes the mechanism rather than fixing one framework's flag names, and readers should check their own framework's documentation for the version in use.

Seven-step diagnosis

  1. Characterise the shape. Decide which of the three shapes it is: a crash in a training step (follow T1 and T3), a crash only in validation (follow T2), or a crash while loading, before any step (follow article #179 or #552). Record the baseline: the model, the rank, the micro-batch size, the accumulation steps, the sequence length, whether gradient checkpointing is on or off, the optimiser, and the training framework and version.
  2. Check the state. Run training once, watch the `nvidia-smi` VRAM peak during training (an auxiliary observation), and record which step crashed and in which phase it crashed — that is the first half of T2.
  3. Compare the phases. Decide whether the crash happens in a training step or only in validation sampling (T2). If it happens only in validation, offload the optimiser state during validation or shrink the validation resolution or frame count.
  4. Compare gradient checkpointing. Run the checkpointing off-against-on comparison (T1). If turning it on lets the run complete, the activations layer is the main cause, and the 20–30% slowdown is the price, not a fault.
  5. Compare gradient accumulation. With the effective batch unchanged, drop the micro-batch to 1 and raise the accumulation steps to 4 (T3). If the run completes, the per-step peak is the main cause, and the effective batch does not need to change.
  6. Run the support comparisons. Step through the rank ladder (T4) and the 8-bit optimiser (T5). These are decisive only at the edge, so do not treat them as the first choice — T1, T2, and T3 come first.
  7. Stop. If the three tests plus the support tests still do not separate the cause, record eight numbers — the model, the rank, the micro-batch size, the accumulation steps, the checkpointing state, the optimiser, the crash phase, and the VRAM peak — and bring them to a check. Do not reinstall the driver or PyTorch one after another; reinstalling cannot change a training switch.

Three decisive tests

Each test changes exactly one variable and records the same two outcomes: whether the run crashes with `CUDA out of memory` or completes, and the `nvidia-smi` VRAM peak. Keep the model, the rank, the micro-batch size, the sequence length, and the optimiser fixed unless the test itself says to change one of them.

T1: Gradient checkpointing comparison — the same training run, the same settings, checkpointing off against on, measuring the activation peak and whether the run completes

Keep every training setting fixed — the model, the rank, the micro-batch size, the sequence length, and the optimiser. First run with gradient checkpointing off, recording which step crashes and the `nvidia-smi` VRAM peak. Then run again with gradient checkpointing on, recording the same two numbers.

Why this test is new: "gradient checkpoint" and the Chinese term for gradient checkpointing appear zero times in either language across the whole article library. Article #552's test T3 changes the `expandable_segments` switch, a PyTorch allocator switch, and measures whether a fragmentation out-of-memory error still happens; T1 changes the checkpointing switch and measures the activation peak and whether the run completes, plus the speed cost. The mechanisms are entirely different — allocator fragmentation against whether activations are stored. Article #156 states the four-pool principle — that training holds weights, gradients, intermediate results, and optimiser state — and then states explicitly that it covers the AI part only as a principle, teaching no switch and no checkpointing.

T2: Phase-timing comparison — record which phase the crash happens in: a training step against validation sampling

Read the training log line by line and record where the run was when the out-of-memory error appeared: in a training step (step N, while the loss was being computed) or in validation sampling (while the model was generating validation video or images).

Note that a validation-phase crash is not "the model is too big". It is two large parts colliding at the same moment — the optimiser state and the VAE decoder — and the fix is to separate them in time, not to shrink the model.

Why this test is new: no article in the library teaches using "which phase crashed" as a decisive test. Article #552 test T1 reads the PyTorch error-message numbers (allocated against reserved-but-unallocated), with the error-message numbers as the variable and the allocator state as the outcome; T2's variable is the phase of the crash and its outcome is a training-step crash against a validation-sampling crash. Article #553's preemption test is about vLLM inference requests queuing, with phases of "starting" against "running requests", not training against validation. Article #562 is about the training data pipeline — data loading against computation — not about a training step against validation.

T3: Gradient-accumulation comparison — the effective batch unchanged, the micro-batch dropped from 4 to 1 with accumulation 4, watching whether the run completes

Fix the effective batch — for example, 4. First run with a micro-batch of 4 and 1 accumulation step, recording whether it crashes and the VRAM peak. Then run with a micro-batch of 1 and 4 accumulation steps — the effective batch is still 4 — recording the same two numbers.

Note that gradient accumulation is not "shrinking the batch". The effective batch stays the same, so the learning-rate schedule does not need to change. That distinction is exactly the point of T3: the effective batch is explicitly held fixed at 4 for the comparison, while article #552 test T5 only mentions compensating with gradient accumulation in one line and fixes no such protocol.

Why this test is new: article #552 test T5 is a "batch and model shrink" test — it shrinks the micro-batch to 1 and compensates with gradient accumulation ("gradient accumulation" appears once in the whole library in each language, in #552 test T5), or drops the model down one quantisation level, the two offered as alternatives, with no explicit fixed-effective-batch protocol. T3's variable is the micro-batch size while the effective batch is explicitly held fixed at 4 (4×1 against 1×4), and its outcome is "out of memory or completes, at the same effective batch". T5 fixes no effective-batch protocol and T3 does — the two tests differ in the comparison they run, not two ways of running the same fork — the same independence argument as article #561 test T3 against article #555 test T6. Article #562 covers `num_workers` and data placement, not gradient accumulation.

Support tests

These are part of this article, but they are deliberately not counted among the three decisive tests, because each one is a weak lever for LoRA training and is decisive only at the edge.

T4: LoRA rank ladder. Keep the same training run and step the rank through 8, 16, 32, and 64, recording at each step whether the run crashes or completes and the VRAM peak. If a smaller rank completes and a larger rank crashes, the adapter-parameter layer is confirmed. The honest note must travel with the result: the finetune-calc formula estimate for an 8B model is 16.5 GiB total memory at rank 8 against 17.5 GiB at rank 64 — an eightfold increase in rank adds about 1 GiB — so away from the edge, T4 cannot separate the layer, because rank 8 and rank 64 crash together or complete together. A smaller rank is also not free: it learns less new knowledge, so there is an accuracy cost.

T5: 8-bit optimiser comparison. Keep the same training run and change the optimiser from AdamW to AdamW 8-bit (bitsandbytes), recording whether the run crashes or completes and the VRAM peak. If the change lets the run complete, the optimiser-state layer is confirmed. The honest note must travel with the result: for LoRA the absolute saving is small — the Motion-LoRA example at rank 16 saves about 180 MB, from about 240 MB of optimiser state to about 60 MB — and the finetune-calc guide calls this lever irrelevant for LoRA and QLoRA. T5 is decisive only at a high rank, where the adapter has many parameters, or in a validation-phase crash, where the AdamW state and the VAE decoder cannot coexist.

Auxiliary observations

These are useful supporting observations. They are deliberately not counted among the three decisive tests.

Batch-size ladder. Shrink the micro-batch from large to small and watch whether the run crashes or completes. This is deliberately not counted among the three tests: its variable is the batch size, which is article #552 test T5's variable, and the same variable is not counted twice.

The `nvidia-smi` VRAM reading during training. Use it only to confirm the premise — what the VRAM peak is during training. It is not a decisive test in this article, because it cannot tell which pool overflowed.

Resolution and sequence-length ladder. Shrink the training image resolution or the text sequence length, and the activation peak falls. This is deliberately not counted among the three tests: its variable, the input size, is close to the "model shrink" family in article #552 test T5, and the resolution ladder belongs mainly to the LTX video-training context, so a general LoRA article should not present it as a main test.

The three tests, in one table

TestVariable changedOutcome variablesWhat a positive result means
T1: checkpointing off vs onGradient checkpointing stateVRAM peak; crash or complete; speed costActivations pool overflowed
T2: training step vs validationPhase of the crashTraining-step crash vs validation crashOptimiser state and VAE decoder collide in validation
T3: micro-batch 4 vs 1, accumulation 1 vs 4Micro-batch size, effective batch unchangedCrash or complete at the same effective batchPer-step activation peak is the cause
T4 (support): rank 8 → 64LoRA rankCrash or complete; VRAM peakAdapter pool matters — only at the edge (~1 GiB)
T5 (support): AdamW vs AdamW 8-bitOptimiser precisionCrash or complete; VRAM peakOptimiser-state pool matters — only ~180 MB at rank 16

Common misconceptions

  1. "LoRA training always saves memory, so a crash means the card is not big enough." Wrong. LoRA saves only the gradient pool and the optimiser-state pool; the activations pool is completely unaffected by LoRA. The Medium guide states it directly: after switching to LoRA and still running out of memory, the batch size or sequence length is probably the real problem. Run T1 first, and do not start by changing to a larger card.
  2. "A training out-of-memory error has the same fix as an inference out-of-memory error." Wrong. Article #552's `expandable_segments` is an allocator switch; it does not make activations smaller and it does not make optimiser state smaller. A training crash needs training switches — checkpointing, accumulation, rank, and optimiser — not an allocator switch.
  3. "A larger rank is always better, and rank is the main cause of the crash." Wrong. The finetune-calc formula estimate puts it plainly: on an 8B model, rank 8 to rank 64 adds only about 1 GiB of total memory, because the frozen base model is the large part. Rank is decisive only at the edge; away from the edge, rank 8 and rank 64 crash together. Run T1, T2, and T3 first, and do not start by blaming the rank.
  4. "An 8-bit optimiser will always save a LoRA run." Wrong. For LoRA, the optimiser state covers only the adapter: the Motion-LoRA example at rank 16 saves only about 180 MB, and the finetune-calc guide calls this lever irrelevant for LoRA and QLoRA. The 8-bit optimiser is a support test, not a first choice.
  5. "A smaller batch means slower training and worse learning." Wrong. Gradient accumulation keeps the effective batch unchanged, so the learning-rate schedule does not need to change; a smaller micro-batch only lowers the per-step peak, it does not make the model learn worse. That distinction is exactly what T3 measures.
  6. "A crash in validation means the model is too big." Wrong. A validation-phase crash is often the AdamW state and the VAE decoder being unable to coexist on the GPU at the same moment, not the model itself being too big. Run T2 to separate the phase first, and do not start by shrinking the model.

Boundary cases: what this article is not

SituationWhich route appliesWhy it is not this article
Inference or generation crashes with `CUDA out of memory`#552 / #553Allocator or vLLM budget problem, not a training-pool problem
The model crashes with OOM while loading, before training starts#179 / #552Planning layer or allocator layer; training has not begun
An Ollama model runs on the CPU, loading but not using the GPU#556`num_gpu` layer count, not a training switch
An Ollama model is slow only when asked again after minutes#555Idle unloading, not training parameters
Training data loads slowly and the GPU keeps waiting for data#562Data-loading bottleneck, not a training memory pool
The model cannot fit at all, or sizing a card before purchase#179Planning arithmetic, not run-time training diagnosis
Docker cannot find the graphics card at all#554Container runtime layer; the program never had a device
Training loss does not fall, or the results are poorModel / data layerAccuracy problem, not a memory problem
ComfyUI crashes with OOM while decoding with the VAEBackup item FR3VAE decoding phase timing and tiled VAE, at most two tests, not enough for three

Neighbour articles and the boundary map

This article is #564, and its companion in the same batch is #563, which covers an external monitor whose brightness cannot be changed from software. The two share a batch and a diagnostic style — five layers, seven steps, three decisive tests — but nothing else: one is a monitor command channel, the other is a training memory pool, and they share no test, no variable, and no outcome.

The closest neighbours, read closely. Article #552 is the PyTorch out-of-memory article. Its boundary states that vLLM, llama.cpp, and Ollama each have their own allocator and KV Cache management, that it covers PyTorch only, and that other frameworks' out-of-memory errors should be investigated with their own tools. Its tests are T1 reading the error-message numbers (allocated against reserved-but-unallocated), T2 a fresh process, T3 the `expandable_segments` switch, T4 the peak and `empty_cache`, and T5 batch and model shrinking — all allocator-layer tests, none of them a training-pool test. The three tests here use variables — the checkpointing state, the crash phase, and the micro-batch size with the effective batch unchanged — that are all different from #552's five. Article #156 is the VRAM-full article. It states the four-pool principle — that training holds weights, gradients, intermediate results, and optimiser state beyond the weights — and then states explicitly that it covers the AI part only as a principle and does not promise that a particular model will run on a particular card. It teaches no switch and no checkpointing, and the word "optimiser" appears in it twice, in that principle paragraph; a string appearing is not the same as a mechanism being covered. Article #553 is the vLLM article: KV Cache budget, PagedAttention blocks, `gpu_memory_utilization`, startup failure and mid-run preemption — all inference-service layer, with no training phase in it. Article #555 is the Ollama lifecycle article: its test T6 varies model size and `num_ctx` and measures whether a model stays loaded, while this article's test T4 varies the LoRA rank and measures whether a run crashes or completes. The two variables never change each other's outcome. Article #556 is the Ollama-on-CPU article: `num_gpu` in three settings, the PROCESSOR column of `ollama ps`, and a layer-count against speed gradient — none of its variables is a training switch. Article #179 is the planning article: quantisation levels, offload cost, and sizing a card before purchase, with zero occurrences of "LoRA" and zero of gradient checkpointing. Article #562 is the training-data-loading article: `num_workers`, data placement, and waiting time, with zero occurrences of "LoRA" and zero of gradient checkpointing.

The library scan. "LoRA" in Chinese appears zero times across the library, and "lora" in English appears 27 times, all of them substring false positives — "discoloration" 24 times, "exploration" twice, and "Valorant" once — with two more "Valorant" hits in Chinese. "Gradient checkpoint" and "gradient checkpointing" appear zero times in either language; "gradient accumulation" appears once in each language, in article #552 test T5. "優化器" in Chinese appears twice, in article #156's principle paragraph, and "optimizer" in English appears twice, in the same paragraph.

Sources and honesty gaps

The facts in this article come from the following sources, checked by search on 2026-11-23: the LTX guide "LoRA Training Problems For Video Models", at https://staging.ltx.io/blog/lora-training-problems, for the statement that `CUDA out of memory` is the most common LoRA training problem on video models, for the five memory switches — `enable_gradient_checkpointing: true`, `batch_size: 1`, `gradient_accumulation_steps: 4`, `optimizer_type: "adamw8bit"`, `load_text_encoder_in_8bit: true`, and `quantization: "int8-quanto"` — for the statement that gradient checkpointing trades speed for memory, and for the statement that an out-of-memory error only during validation is usually the AdamW state and the VAE decoder being unable to coexist on the GPU, fixed by `offload_optimizer_during_validation: true`; the finetune-calc guide "Fine-Tuning Memory Levers", at https://www.finetune-calc.com/guides/training-memory-optimizer-checkpointing-batch, for Adam at 8 bytes per parameter and 8-bit Adam at 2 bytes, for full fine-tuning on an 8B model at 121.1 GiB with Adam against 76.2 GiB with 8-bit Adam, for the statement that the optimiser lever is irrelevant for LoRA and QLoRA because it holds only the adapters, for the checkpointing estimate of 5.4 GiB on against 12.0 GiB off for QLoRA on an 8B model at batch 4 and sequence length 2048, for the rank figures of 14.7 million trainable parameters and 16.5 GiB at rank 8 against 117.4 million and 17.5 GiB at rank 64, and for the note that batch 16 at sequence length 2048 costs the same as batch 4 at sequence length 8192, at 32,768 tokens per step; the Motion-LoRA DeepWiki page "Memory Optimization", at https://deepwiki.com/tykim0507/Motion-LoRA/7.2-memory-optimization, for gradient checkpointing discarding intermediate activations in the forward pass and recomputing them in the backward pass, for the 50–70% activation reduction and 20–30% slowdown, for the 8-bit optimiser cutting optimiser-state memory by about 75%, and for the rank-16 example of about 240 MB of optimiser state with standard AdamW against about 60 MB with AdamW 8-bit; and the Medium guide "Common causes of out-of-memory errors when training AI models", at https://medium.com/@prateeknavani808/common-causes-of-out-of-memory-errors-when-training-ai-models-8359dd32dbce, for the GPU holding weights, gradients, an fp32 master copy, Adam momentum and variance, and activations at the same time, at roughly 16 bytes per parameter before a single activation is counted, for the statement that LoRA and quantisation shrink the parts that scale with parameters and do nothing for activations, and for the fixes of a smaller micro-batch with gradient accumulation, gradient checkpointing, FlashAttention, and an 8-bit optimiser.

Three honesty gaps must be stated plainly. First, there was no local reproduction: no LoRA training run was executed on a local machine for this article, so the actual effect of the checkpointing switch, the rank ladder, the 8-bit optimiser, and validation-phase offloading all come from the external sources and formula estimates listed above, and behaviour may differ between frameworks and versions. Readers should take their own framework version's behaviour as authoritative. Second, the worked numbers — 5.4 GiB against 12.0 GiB, 16.5 GiB against 17.5 GiB, and about 240 MB against about 60 MB — are a finetune-calc formula estimate for a Llama 3.1 8B model and a Motion-LoRA 1.6B example, not general rules; tests T1, T4, and T5 use only the direction of the change, never a fixed number. Third, the switch names differ between frameworks — TRL, PEFT, kohya, diffusers, and the LTX trainer spell them differently — so this article describes the mechanism rather than fixing one framework's flag names, and readers should check their own framework's documentation for the version in use. Two source conflicts were handled by stating the scale rather than picking a side: finetune-calc calls the 8-bit optimiser irrelevant for LoRA while LTX lists it among its five memory switches, and the two agree once the scale is stated — about 45 GiB saved in full fine-tuning against about 180 MB in LoRA at rank 16 — so T5 is a support test, not a main test; and the Medium guide's 16 bytes per parameter and finetune-calc's split counting (weights 2 bytes, gradients 2 bytes, fp32 master 4 bytes, Adam 8 bytes) are two ways of counting the same thing, so this article states no single total.

Frequently asked questions

Is the card too small for my model?

Because loading the model and training it hold different things. Loading holds mainly the weights; training also holds gradients, optimiser state, and activations, and the activations pool grows with every step's batch and sequence length until the total passes the card's memory. A model that loads fine can still crash in training, and the crash arriving halfway through is the signature of a pool that grows during training, not of a model that is too big to load. Not necessarily, and that is the wrong first conclusion. LoRA shrinks the gradient and optimiser-state pools but does nothing to the activations pool, so a run can crash on activations on a card that holds the model easily. Run test T1 — gradient checkpointing off against on — before concluding anything about the card size. If checkpointing on lets the run complete, the card was never the problem.

Does gradient checkpointing make training slower?

Yes, by about 20–30%, and that is the price, not a fault. Checkpointing discards intermediate activations during the forward pass and recomputes them during the backward pass, so the same step does more computation and holds far less memory — about 50–70% fewer activations. A run that is slower but completes is a fixed run; a run that is faster but crashes is not a run at all.

Why does my run crash only during validation, when training steps all complete?

Because validation is a different phase with a different memory peak: the AdamW optimiser state and the VAE decoder have to be on the GPU at the same time, and the LTX documentation states that this is usually why an out-of-memory error appears only during validation. The fix is to offload the optimiser state during validation, or to shrink the validation resolution or frame count — not to shrink the model.

Does shrinking the batch change what the model learns?

Shrinking the micro-batch alone, without gradient accumulation, does change the effective batch, and the learning-rate schedule expects a particular effective batch. Shrinking the micro-batch while raising the accumulation steps — test T3 — keeps the effective batch unchanged, so the schedule does not need to change. That is the whole point of T3: the per-step peak falls, and what the model learns does not have to change.

Will a smaller LoRA rank fix the crash?

Usually not, and the arithmetic says why: on an 8B model, rank 8 uses 16.5 GiB total and rank 64 uses 17.5 GiB, so an eightfold increase in rank adds only about 1 GiB. Rank is decisive only when the run is about 1 GiB short. Run T1, T2, and T3 first; only use the rank ladder, test T4, when the run is at the edge.

Will an 8-bit optimiser fix the crash?

Usually not for LoRA, and again the arithmetic says why: at rank 16, the optimiser state falls from about 240 MB to about 60 MB, saving about 180 MB. That is a real saving, but it is small next to a multi-gigabyte activations pool, and the finetune-calc guide calls this lever irrelevant for LoRA and QLoRA. Use it as a support test, test T5, at a high rank or in a validation-phase crash — not as a first choice.

I have run all three tests plus the support tests and still cannot separate the cause. What now?

Record eight numbers — the model, the rank, the micro-batch, the accumulation steps, the checkpointing state, the optimiser, the crash phase, and the VRAM peak — and bring them to a check. Do not reinstall the driver or PyTorch one after another — reinstalling cannot change a training switch. If there is a hardware suspicion (for example, abnormal VRAM readings, or errors midway through training), the card can be taken to the workshop for a further check.

Conclusion

A LoRA run that crashes with `CUDA out of memory` halfway through is a memory-pool problem with a fixed shape: a model that loads, inference that works, and training that holds four pools at once until one of them overflows. The three comparisons in this article — gradient checkpointing off against on, the training step against validation sampling, and a micro-batch of 4 against a micro-batch of 1 with the effective batch unchanged — separate the activations pool, the phase, and the per-step peak with numbers instead of guesses, and each one changes exactly one variable on the same training run. The two support tests — the rank ladder and the 8-bit optimiser — are kept honest about their size: about 1 GiB across an eightfold rank change, and about 180 MB saved at rank 16, so they are used at the edge, not as first choices.

When to seek professional help: if the model crashes while loading, if inference crashes too, or if all three tests plus the support tests fail to separate the cause — or if the VRAM readings during training are abnormal, or the machine crashes — the problem is no longer a training switch. It may involve the driver, the installation, or the hardware itself, and is worth having checked by a technician.

If the tests point to a hardware fault rather than a setting — the card is not detected, the machine crashes, or training fails with an error that no switch changes — the card can be checked at the Shek Mun workshop: Dali Plaza, Room 1209, Shek Mun, Hong Kong. Phone 2186 8010, WhatsApp 6558 6806. Diagnosis and repair pricing follows the workshop's published three-tier range of HK$400–HK$2,800, quoted before any work begins.

Related articles

Related services

If you need Chip-level GPU repair, see these service pages: