Fine-tune LLMs from one YAML. Layer streaming trains an 8B model on a 4 GB laptop GPU.
Python cliconsumer-gpudpofine-tuningggufhuggingfacellmllmopslocal-ailocal-llmloralow-vrammachine-learningollamapeftpythonpytorchqlorasfttransformers
fix(errors): suggest lowering data.max_length on CUDA out-of-memory errors (#1694) (#1708)
Sohaib Kamash30ec887c38bf
diff --git a/changelog.d/0.76.0/1708.fixed.md b/changelog.d/0.76.0/1708.fixed.mdnew file mode 100644index 00000000..03f29d7e--- /dev/null+++ b/changelog.d/0.76.0/1708.fixed.md@@ -0,0 +1,3 @@+- Suggest lowering `data.max_length` alongside `--batch-size` in the+ friendly error hints for `CUDA out of memory` and `OutOfMemoryError`+ (#1694 by @Nick-800 in #1708).diff --git a/src/soup_cli/utils/errors.py b/src/soup_cli/utils/errors.pyindex 5ff50d58..7745f24c 100644--- a/src/soup_cli/utils/errors.py+++ b/src/soup_cli/utils/errors.py@@ -24,8 +24,8 @@ ERROR_MAP = ["GPU ran out of memory during training.",("Try --batch-size <half> or --grad-accum <double> "- "(keeps effective batch size); enable gradient_checkpointing, "- "use 4bit quantization, or use a smaller model."+ "(keeps effective batch size); lower data.max_length; "+ "enable gradient_checkpointing, use 4bit quantization, or use a smaller model."),),(@@ -33,8 +33,8 @@ ERROR_MAP = ["GPU ran out of memory.",("Try --batch-size <half> or --grad-accum <double> "- "(keeps effective batch size); enable gradient_checkpointing, "- "use 4bit quantization, or use a smaller model."+ "(keeps effective batch size); lower data.max_length; "+ "enable gradient_checkpointing, use 4bit quantization, or use a smaller model."),),# Missing optional depsdiff --git a/tests/test_errors.py b/tests/test_errors.pyindex a70e68a1..7e1059f3 100644--- a/tests/test_errors.py+++ b/tests/test_errors.py@@ -30,6 +30,7 @@ def test_cuda_oom_error():# v0.53.4 #11 — message now suggests --batch-size / --grad-accum CLI flags.assert "gradient_checkpointing" in outputassert "4bit" in output+ assert "data.max_length" in outputdef test_missing_fastapi_error():diff --git a/tests/test_issue1694_cuda_oom_max_length_hint.py b/tests/test_issue1694_cuda_oom_max_length_hint.pynew file mode 100644index 00000000..f6f7e7f2--- /dev/null+++ b/tests/test_issue1694_cuda_oom_max_length_hint.py@@ -0,0 +1,56 @@+"""Tests for Issue #1694: CUDA out-of-memory error hints include data.max_length.++Pins that both 'CUDA out of memory' and 'OutOfMemoryError' suggest lowering+data.max_length alongside adjusting batch size / gradient accumulation.+"""++from io import StringIO+from unittest.mock import patch++from rich.console import Console++from soup_cli.utils.errors import ERROR_MAP, format_friendly_error+++def test_cuda_oom_error_suggests_data_max_length():+ """RuntimeError with 'CUDA out of memory' mentions data.max_length."""+ buf = StringIO()+ test_console = Console(file=buf, stderr=False)+ with patch("soup_cli.utils.errors.console", test_console):+ exc = RuntimeError("CUDA out of memory. Tried to allocate 2.00 GiB")+ format_friendly_error(exc, verbose=False)+ output = buf.getvalue()+ assert "data.max_length" in output+ assert "--batch-size" in output+ assert "GPU ran out of memory during training." in output+++def test_out_of_memory_error_type_suggests_data_max_length():+ """OutOfMemoryError exception mentions data.max_length."""+ buf = StringIO()+ test_console = Console(file=buf, stderr=False)++ class OutOfMemoryError(RuntimeError):+ pass++ with patch("soup_cli.utils.errors.console", test_console):+ exc = OutOfMemoryError("simulated out of memory error")+ format_friendly_error(exc, verbose=False)+ output = buf.getvalue()+ assert "data.max_length" in output+ assert "--batch-size" in output+ assert "GPU ran out of memory." in output+++def test_error_map_entries_pin_data_max_length():+ """ERROR_MAP entries for CUDA OOM and OutOfMemoryError explicitly pin data.max_length."""+ oom_entries = [+ (pat, msg, fix)+ for pat, msg, fix in ERROR_MAP+ if pat in ("CUDA out of memory", "OutOfMemoryError")+ ]+ assert len(oom_entries) == 2, f"Expected 2 OOM entries in ERROR_MAP, found {len(oom_entries)}"+ for pat, _msg, fix in oom_entries:+ assert (+ "data.max_length" in fix+ ), f"ERROR_MAP pattern {pat!r} fix suggestion does not name data.max_length: {fix!r}"