1
0
Fork 0
mirror of https://github.com/p-e-w/heretic.git synced 2026-12-03 18:42:57 +07:00

[GH-ISSUE #96] CUDA out of memory issue #51

Closed
opened 2026-11-01 04:16:59 +07:00 by bsakaguchi · 6 comments
Owner

Originally created by @Hotohori on GitHub (Jan 3, 2026).
Original GitHub issue: https://github.com/p-e-w/heretic/issues/96

I switched because of the support of max_memory to the actual build (so NOT v1.1.0) and it was running without any problem to the end until I need to selected which trial I want to save locally.

I select a trial, give it a name and when it should start saving I directly get a "CUDA out of memory" error. The app still runs, but it happened 3 times again, then I switched back to the trial selection, select the same one again and this time the app crashed completely with the same message.

Don't know what issue it is, maybe a memory handling problem.

I tried to use heretic on my local RTX 4090 on the Mistral Nemo (12B) model which didn't fully goes into VRAM. I run into a out of memory issue with 1.1.0 and could only use a batch size of 32, failed on 64, with limiting the VRAM to 18GB I could use a batch size of 128 what, even when more of the model is on CPU, still a lot faster. But I hit that problem at the end.

Nvidia-smi (I'm on CachyOS) said heretic used 22,5GB VRAM while I only selected a trail to save, so before saving.

I added my tries to save it with all errors until the app crashed into the log.txt.

log.txt

Originally created by @Hotohori on GitHub (Jan 3, 2026). Original GitHub issue: https://github.com/p-e-w/heretic/issues/96 I switched because of the support of max_memory to the actual build (so NOT v1.1.0) and it was running without any problem to the end until I need to selected which trial I want to save locally. I select a trial, give it a name and when it should start saving I directly get a "CUDA out of memory" error. The app still runs, but it happened 3 times again, then I switched back to the trial selection, select the same one again and this time the app crashed completely with the same message. Don't know what issue it is, maybe a memory handling problem. I tried to use heretic on my local RTX 4090 on the Mistral Nemo (12B) model which didn't fully goes into VRAM. I run into a out of memory issue with 1.1.0 and could only use a batch size of 32, failed on 64, with limiting the VRAM to 18GB I could use a batch size of 128 what, even when more of the model is on CPU, still a lot faster. But I hit that problem at the end. Nvidia-smi (I'm on CachyOS) said heretic used 22,5GB VRAM while I only selected a trail to save, so before saving. I added my tries to save it with all errors until the app crashed into the log.txt. [log.txt](https://github.com/user-attachments/files/24413327/log.txt)
Author
Owner

@Hotohori commented on GitHub (Jan 3, 2026):

Reduced the max memory to 16GB instead of 18GB and again, as soon I want to save it CUDA out of memory. Another 6 hour wasted... Have enough from this BS, at least for the moment.

<!-- gh-comment-id:3707398623 --> @Hotohori commented on GitHub (Jan 3, 2026): Reduced the max memory to 16GB instead of 18GB and again, as soon I want to save it CUDA out of memory. Another 6 hour wasted... Have enough from this BS, at least for the moment.
Author
Owner

@p-e-w commented on GitHub (Jan 4, 2026):

This looks like a memory leak of some kind. If possible, please Git bisect the problem to identify which commit introduced it. Note that you do not have to do a full run to test it; just run Heretic with --n-trials 1 and you will get the trial selection menu immediately (you can also press Ctrl+C during any trial to get the menu).

<!-- gh-comment-id:3707867592 --> @p-e-w commented on GitHub (Jan 4, 2026): This looks like a memory leak of some kind. If possible, please Git bisect the problem to identify which commit introduced it. Note that you do *not* have to do a full run to test it; just run Heretic with `--n-trials 1` and you will get the trial selection menu immediately (you can also press Ctrl+C during any trial to get the menu).
Author
Owner

@mightykatun commented on GitHub (Mar 26, 2026):

Hi, I am encountering the same issue with openai/gpt-oss-120b with an RXT4090, getting almost the same output with or without the --max-memory flag.

Fails too with a smaller model (tried openai/gpt-oss-20b), but later. I don't know it it's a requirement to be able to fit the entire model in the gpu?

Log for openai/gpt-oss-120b
heretic --model openai/gpt-oss-120b --max-memory '{"0": "16GB", "cpu": "100GB"}'
█░█░█▀▀░█▀▄░█▀▀░▀█▀░█░█▀▀  v1.2.0
█▀█░█▀▀░█▀▄░█▀▀░░█░░█░█░░
▀░▀░▀▀▀░▀░▀░▀▀▀░░▀░░▀░▀▀▀  https://github.com/p-e-w/heretic

Detected 1 CUDA device(s):
* GPU 0: NVIDIA GeForce RTX 4090

Loading model openai/gpt-oss-120b...
Fetching 41 files: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 41/41 [00:00<00:00, 191073.85it/s]
Fetching 41 files: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 41/41 [00:00<00:00, 5942.17it/s]
Loading checkpoint shards:  27%|█████████████████████████████████▊                                                                                             | 4/15 [00:01<00:04,  2.22it/s]
Failed (CUDA out of memory. Tried to allocate 1014.00 MiB. GPU 0 has a total capacity of 23.52 GiB of which 29.06 MiB is free. Process 1747 has 2.97 GiB memory in use. Process 1619 has 1.10 
GiB memory in use. Including non-PyTorch memory, this process has 19.40 GiB memory in use. Of the allocated memory 18.97 GiB is allocated by PyTorch, and 47.62 MiB is reserved by PyTorch but
unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation.  See documentation for Memory Management  
(https://docs.pytorch.org/docs/stable/notes/cuda.html#optimizing-memory-usage-with-pytorch-cuda-alloc-conf))
Fetching 41 files: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 41/41 [00:00<00:00, 10595.59it/s]
Fetching 41 files: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 41/41 [00:00<00:00, 4380.53it/s]
Loading checkpoint shards:   0%|                                                                                                                                       | 0/15 [00:00<?, ?it/s]
Failed (CUDA out of memory. Tried to allocate 508.00 MiB. GPU 0 has a total capacity of 23.52 GiB of which 97.06 MiB is free. Process 1747 has 2.97 GiB memory in use. Process 1619 has 1.10 
GiB memory in use. Including non-PyTorch memory, this process has 19.33 GiB memory in use. Of the allocated memory 18.92 GiB is allocated by PyTorch, and 30.28 MiB is reserved by PyTorch but
unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation.  See documentation for Memory Management  
(https://docs.pytorch.org/docs/stable/notes/cuda.html#optimizing-memory-usage-with-pytorch-cuda-alloc-conf))
Fetching 41 files: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 41/41 [00:00<00:00, 10088.97it/s]
Fetching 41 files: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 41/41 [00:00<00:00, 5208.74it/s]
Loading checkpoint shards:  27%|█████████████████████████████████▊                                                                                             | 4/15 [00:01<00:04,  2.23it/s]
Failed (CUDA out of memory. Tried to allocate 1014.00 MiB. GPU 0 has a total capacity of 23.52 GiB of which 29.06 MiB is free. Process 1747 has 2.97 GiB memory in use. Process 1619 has 1.10 
GiB memory in use. Including non-PyTorch memory, this process has 19.40 GiB memory in use. Of the allocated memory 18.97 GiB is allocated by PyTorch, and 47.62 MiB is reserved by PyTorch but
unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation.  See documentation for Memory Management  
(https://docs.pytorch.org/docs/stable/notes/cuda.html#optimizing-memory-usage-with-pytorch-cuda-alloc-conf))
Fetching 41 files: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 41/41 [00:00<00:00, 8755.93it/s]
Fetching 41 files: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 41/41 [00:00<00:00, 17034.82it/s]
Loading checkpoint shards:   0%|                                                                                                                                       | 0/15 [00:00<?, ?it/s]
Failed (CUDA out of memory. Tried to allocate 508.00 MiB. GPU 0 has a total capacity of 23.52 GiB of which 97.06 MiB is free. Process 1747 has 2.97 GiB memory in use. Process 1619 has 1.10 
GiB memory in use. Including non-PyTorch memory, this process has 19.33 GiB memory in use. Of the allocated memory 18.92 GiB is allocated by PyTorch, and 30.28 MiB is reserved by PyTorch but
unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation.  See documentation for Memory Management  
(https://docs.pytorch.org/docs/stable/notes/cuda.html#optimizing-memory-usage-with-pytorch-cuda-alloc-conf))
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /home/user/heretic/.venv/bin/heretic:7 in <module>                                               │
│                                                                                                  │
│   4 if __name__ == '__main__':                                                                   │
│   5 │   if sys.argv[0].endswith('.exe'):                                                         │
│   6 │   │   sys.argv[0] = sys.argv[0][:-4]                                                       │
│ ❱ 7 │   sys.exit(main())                                                                         │
│   8                                                                                              │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/heretic/main.py:891 in main                │
│                                                                                                  │
│   888 │   install()                                                                              │
│   889 │                                                                                          │
│   890 │   try:                                                                                   │
│ ❱ 891 │   │   run()                                                                              │
│   892 │   except BaseException as error:                                                         │
│   893 │   │   # Transformers appears to handle KeyboardInterrupt (or BaseException)              │
│   894 │   │   # internally in some places, which can re-raise a different error in the handler   │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/heretic/main.py:312 in run                 │
│                                                                                                  │
│   309 │   │   elif choice is None or choice == "":                                               │
│   310 │   │   │   return                                                                         │
│   311 │                                                                                          │
│ ❱ 312 │   model = Model(settings)                                                                │
│   313 │   print()                                                                                │
│   314 │   print_memory_usage()                                                                   │
│   315                                                                                            │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/heretic/model.py:145 in __init__           │
│                                                                                                  │
│   142 │   │   │   break                                                                          │
│   143 │   │                                                                                      │
│   144 │   │   if self.model is None:                                                             │
│ ❱ 145 │   │   │   raise Exception("Failed to load model with all configured dtypes.")            │
│   146 │   │                                                                                      │
│   147 │   │   self._apply_lora()                                                                 │
│   148                                                                                            │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
Exception: Failed to load model with all configured dtypes.
Log for openai/gpt-oss-20b
heretic --model openai/gpt-oss-20b
█░█░█▀▀░█▀▄░█▀▀░▀█▀░█░█▀▀  v1.2.0
█▀█░█▀▀░█▀▄░█▀▀░░█░░█░█░░
▀░▀░▀▀▀░▀░▀░▀▀▀░░▀░░▀░▀▀▀  https://github.com/p-e-w/heretic

Detected 1 CUDA device(s):
* GPU 0: NVIDIA GeForce RTX 4090

Loading model openai/gpt-oss-20b...
Fetching 41 files: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 41/41 [00:00<00:00, 271668.98it/s]
Fetching 41 files: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 41/41 [00:00<00:00, 23762.12it/s]
Loading checkpoint shards: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:01<00:00,  2.00it/s]
Ok
* LoRA adapters initialized (targets: o_proj)
* Transformer model with 24 layers
* Abliterable components:
  * attn.o_proj: 1 modules per layer

Resident system RAM: 1.66 GB
Allocated GPU VRAM: 12.84 GB
Reserved GPU VRAM: 12.92 GB

Loading good prompts from mlabonne/harmless_alpaca...
* 400 prompts loaded

Loading bad prompts from mlabonne/harmful_behaviors...
* 400 prompts loaded

Determining optimal batch size...
* Trying batch size 1... Ok (30 tokens/s)
* Trying batch size 2... Ok (59 tokens/s)
* Trying batch size 4... Ok (116 tokens/s)
* Trying batch size 8... Ok (231 tokens/s)
* Trying batch size 16... Ok (453 tokens/s)
* Trying batch size 32... Ok (808 tokens/s)
* Trying batch size 64... Ok (1426 tokens/s)
* Trying batch size 128... Failed (CUDA out of memory. Tried to allocate 228.00 MiB. GPU 0 has a total capacity of 23.52 GiB of which 76.19 MiB is free. Process 1747 has 2.97 GiB memory in use. Process 1619 has 1.10 
GiB memory in use. Process 30526 has 526.00 MiB memory in use. Process 36991 has 860.00 MiB memory in use. Process 36960 has 1.17 GiB memory in use. Process 38806 has 423.94 MiB memory in 
use. Process 38800 has 423.94 MiB memory in use. Including non-PyTorch memory, this process has 15.98 GiB memory in use. Of the allocated memory 14.54 GiB is allocated by PyTorch, and 
1009.46 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation.  See 
documentation for Memory Management  (https://docs.pytorch.org/docs/stable/notes/cuda.html#optimizing-memory-usage-with-pytorch-cuda-alloc-conf))
* Chosen batch size: 64

Checking for common response prefix...
* Prefix found: '<|channel|>analysis<|message|><|end|><|start|>assistant<|channel|>final<|message|>'

Loading good evaluation prompts from mlabonne/harmless_alpaca...
* 100 prompts loaded
* Obtaining first-token probability distributions...

Loading bad evaluation prompts from mlabonne/harmful_behaviors...
* 100 prompts loaded
* Counting model refusals...
* Initial refusals: 98/100

Calculating per-layer refusal directions...
* Obtaining residuals for good prompts...
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /home/user/heretic/.venv/bin/heretic:7 in <module>                                               │
│                                                                                                  │
│   4 if __name__ == '__main__':                                                                   │
│   5 │   if sys.argv[0].endswith('.exe'):                                                         │
│   6 │   │   sys.argv[0] = sys.argv[0][:-4]                                                       │
│ ❱ 7 │   sys.exit(main())                                                                         │
│   8                                                                                              │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/heretic/main.py:891 in main                │
│                                                                                                  │
│   888 │   install()                                                                              │
│   889 │                                                                                          │
│   890 │   try:                                                                                   │
│ ❱ 891 │   │   run()                                                                              │
│   892 │   except BaseException as error:                                                         │
│   893 │   │   # Transformers appears to handle KeyboardInterrupt (or BaseException)              │
│   894 │   │   # internally in some places, which can re-raise a different error in the handler   │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/heretic/main.py:417 in run                 │
│                                                                                                  │
│   414 │   print()                                                                                │
│   415 │   print("Calculating per-layer refusal directions...")                                   │
│   416 │   print("* Obtaining residuals for good prompts...")                                     │
│ ❱ 417 │   good_residuals = model.get_residuals_batched(good_prompts)                             │
│   418 │   print("* Obtaining residuals for bad prompts...")                                      │
│   419 │   bad_residuals = model.get_residuals_batched(bad_prompts)                               │
│   420                                                                                            │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/heretic/model.py:652 in                    │
│ get_residuals_batched                                                                            │
│                                                                                                  │
│   649 │   │   residuals = []                                                                     │
│   650 │   │                                                                                      │
│   651 │   │   for batch in batchify(prompts, self.settings.batch_size):                          │
│ ❱ 652 │   │   │   residuals.append(self.get_residuals(batch))                                    │
│   653 │   │                                                                                      │
│   654 │   │   return torch.cat(residuals, dim=0)                                                 │
│   655                                                                                            │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/heretic/model.py:606 in get_residuals      │
│                                                                                                  │
│   603 │   def get_residuals(self, prompts: list[Prompt]) -> Tensor:                              │
│   604 │   │   # We only generate one token, and we return the residual vectors                   │
│   605 │   │   # at that token position, for each prompt and layer.                               │
│ ❱ 606 │   │   _, outputs = self.generate(                                                        │
│   607 │   │   │   prompts,                                                                       │
│   608 │   │   │   max_new_tokens=1,                                                              │
│   609 │   │   │   output_hidden_states=True,                                                     │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/heretic/model.py:560 in generate           │
│                                                                                                  │
│   557 │   │                                                                                      │
│   558 │   │   # FIXME: The type checker has been disabled here because of the extremely comple   │
│   559 │   │   #        interplay between different generate() signatures and dynamic delegatio   │
│ ❱ 560 │   │   outputs = self.model.generate(                                                     │
│   561 │   │   │   **inputs,                                                                      │
│   562 │   │   │   **kwargs,                                                                      │
│   563 │   │   │   pad_token_id=self.tokenizer.pad_token_id,                                      │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/peft/peft_model.py:2048 in generate        │
│                                                                                                  │
│   2045 │   │   │   │   kwargs = get_alora_offsets_for_generate(self, *args, **kwargs)            │
│   2046 │   │   │   │   with self._enable_peft_forward_hooks(*args, **kwargs):                    │
│   2047 │   │   │   │   │   kwargs = {k: v for k, v in kwargs.items() if k not in self.special_p  │
│ ❱ 2048 │   │   │   │   │   outputs = self.base_model.generate(*args, **kwargs)                   │
│   2049 │   │   │   else:                                                                         │
│   2050 │   │   │   │   outputs = self.base_model.generate(**kwargs)                              │
│   2051 │   │   except:                                                                           │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/torch/utils/_contextlib.py:124 in          │
│ decorate_context                                                                                 │
│                                                                                                  │
│   121 │   def decorate_context(*args, **kwargs):                                                 │
│   122 │   │   # pyrefly: ignore [bad-context-manager]                                            │
│   123 │   │   with ctx_factory():                                                                │
│ ❱ 124 │   │   │   return func(*args, **kwargs)                                                   │
│   125 │                                                                                          │
│   126 │   return decorate_context                                                                │
│   127                                                                                            │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/generation/utils.py:2566 in   │
│ generate                                                                                         │
│                                                                                                  │
│   2563 │   │   model_kwargs["use_cache"] = generation_config.use_cache                           │
│   2564 │   │                                                                                     │
│   2565 │   │   # 9. Call generation mode                                                         │
│ ❱ 2566 │   │   result = decoding_method(                                                         │
│   2567 │   │   │   self,                                                                         │
│   2568 │   │   │   input_ids,                                                                    │
│   2569 │   │   │   logits_processor=prepared_logits_processor,                                   │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/generation/utils.py:2786 in   │
│ _sample                                                                                          │
│                                                                                                  │
│   2783 │   │   │   model_inputs = self.prepare_inputs_for_generation(input_ids, **model_kwargs)  │
│   2784 │   │   │                                                                                 │
│   2785 │   │   │   if is_prefill:                                                                │
│ ❱ 2786 │   │   │   │   outputs = self(**model_inputs, return_dict=True)                          │
│   2787 │   │   │   │   is_prefill = False                                                        │
│   2788 │   │   │   else:                                                                         │
│   2789 │   │   │   │   outputs = model_forward(**model_inputs, return_dict=True)                 │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/torch/nn/modules/module.py:1779 in         │
│ _wrapped_call_impl                                                                               │
│                                                                                                  │
│   1776 │   │   if self._compiled_call_impl is not None:                                          │
│   1777 │   │   │   return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]        │
│   1778 │   │   else:                                                                             │
│ ❱ 1779 │   │   │   return self._call_impl(*args, **kwargs)                                       │
│   1780 │                                                                                         │
│   1781 │   # torchrec tests the code consistency with the following code                         │
│   1782 │   # fmt: off                                                                            │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/torch/nn/modules/module.py:1790 in         │
│ _call_impl                                                                                       │
│                                                                                                  │
│   1787 │   │   if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks   │
│   1788 │   │   │   │   or _global_backward_pre_hooks or _global_backward_hooks                   │
│   1789 │   │   │   │   or _global_forward_hooks or _global_forward_pre_hooks):                   │
│ ❱ 1790 │   │   │   return forward_call(*args, **kwargs)                                          │
│   1791 │   │                                                                                     │
│   1792 │   │   result = None                                                                     │
│   1793 │   │   called_always_called_hooks = set()                                                │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/utils/generic.py:918 in       │
│ wrapper                                                                                          │
│                                                                                                  │
│    915 │   │   return_dict_passed = kwargs.pop("return_dict", return_dict)                       │
│    916 │   │   if return_dict_passed is not None:                                                │
│    917 │   │   │   return_dict = return_dict_passed                                              │
│ ❱  918 │   │   output = func(self, *args, **kwargs)                                              │
│    919 │   │   if not return_dict and not isinstance(output, tuple):                             │
│    920 │   │   │   output = output.to_tuple()                                                    │
│    921 │   │   return output                                                                     │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/models/gpt_oss/modeling_gpt_o │
│ ss.py:668 in forward                                                                             │
│                                                                                                  │
│   665 │   │   )                                                                                  │
│   666 │   │                                                                                      │
│   667 │   │   # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)    │
│ ❱ 668 │   │   outputs: MoeModelOutputWithPast = self.model(                                      │
│   669 │   │   │   input_ids=input_ids,                                                           │
│   670 │   │   │   attention_mask=attention_mask,                                                 │
│   671 │   │   │   position_ids=position_ids,                                                     │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/torch/nn/modules/module.py:1779 in         │
│ _wrapped_call_impl                                                                               │
│                                                                                                  │
│   1776 │   │   if self._compiled_call_impl is not None:                                          │
│   1777 │   │   │   return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]        │
│   1778 │   │   else:                                                                             │
│ ❱ 1779 │   │   │   return self._call_impl(*args, **kwargs)                                       │
│   1780 │                                                                                         │
│   1781 │   # torchrec tests the code consistency with the following code                         │
│   1782 │   # fmt: off                                                                            │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/torch/nn/modules/module.py:1790 in         │
│ _call_impl                                                                                       │
│                                                                                                  │
│   1787 │   │   if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks   │
│   1788 │   │   │   │   or _global_backward_pre_hooks or _global_backward_hooks                   │
│   1789 │   │   │   │   or _global_forward_hooks or _global_forward_pre_hooks):                   │
│ ❱ 1790 │   │   │   return forward_call(*args, **kwargs)                                          │
│   1791 │   │                                                                                     │
│   1792 │   │   result = None                                                                     │
│   1793 │   │   called_always_called_hooks = set()                                                │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/utils/generic.py:1072 in      │
│ wrapper                                                                                          │
│                                                                                                  │
│   1069 │   │   │   │   │   │   │   monkey_patched_layers.append((module, original_forward))      │
│   1070 │   │   │                                                                                 │
│   1071 │   │   │   try:                                                                          │
│ ❱ 1072 │   │   │   │   outputs = func(self, *args, **kwargs)                                     │
│   1073 │   │   │   except TypeError as original_exception:                                       │
│   1074 │   │   │   │   # If we get a TypeError, it's possible that the model is not receiving t  │
│   1075 │   │   │   │   # Get a TypeError even after removing the recordable kwargs -> re-raise   │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/models/gpt_oss/modeling_gpt_o │
│ ss.py:507 in forward                                                                             │
│                                                                                                  │
│   504 │   │   position_embeddings = self.rotary_emb(hidden_states, position_ids)                 │
│   505 │   │                                                                                      │
│   506 │   │   for decoder_layer in self.layers:                                                  │
│ ❱ 507 │   │   │   hidden_states = decoder_layer(                                                 │
│   508 │   │   │   │   hidden_states,                                                             │
│   509 │   │   │   │   attention_mask=causal_mask_mapping[decoder_layer.attention_type],          │
│   510 │   │   │   │   position_ids=position_ids,                                                 │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/modeling_layers.py:94 in      │
│ __call__                                                                                         │
│                                                                                                  │
│    91 │   │   │   │   logger.warning_once(message)                                               │
│    92 │   │   │                                                                                  │
│    93 │   │   │   return self._gradient_checkpointing_func(partial(super().__call__, **kwargs)   │
│ ❱  94 │   │   return super().__call__(*args, **kwargs)                                           │
│    95                                                                                            │
│    96                                                                                            │
│    97 @auto_docstring                                                                            │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/torch/nn/modules/module.py:1779 in         │
│ _wrapped_call_impl                                                                               │
│                                                                                                  │
│   1776 │   │   if self._compiled_call_impl is not None:                                          │
│   1777 │   │   │   return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]        │
│   1778 │   │   else:                                                                             │
│ ❱ 1779 │   │   │   return self._call_impl(*args, **kwargs)                                       │
│   1780 │                                                                                         │
│   1781 │   # torchrec tests the code consistency with the following code                         │
│   1782 │   # fmt: off                                                                            │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/torch/nn/modules/module.py:1790 in         │
│ _call_impl                                                                                       │
│                                                                                                  │
│   1787 │   │   if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks   │
│   1788 │   │   │   │   or _global_backward_pre_hooks or _global_backward_hooks                   │
│   1789 │   │   │   │   or _global_forward_hooks or _global_forward_pre_hooks):                   │
│ ❱ 1790 │   │   │   return forward_call(*args, **kwargs)                                          │
│   1791 │   │                                                                                     │
│   1792 │   │   result = None                                                                     │
│   1793 │   │   called_always_called_hooks = set()                                                │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/utils/generic.py:1031 in      │
│ wrapped_forward                                                                                  │
│                                                                                                  │
│   1028 │   │   │   │   │   │   ):                                                                │
│   1029 │   │   │   │   │   │   │   output = orig_forward(*args, **kwargs)                        │
│   1030 │   │   │   │   │   else:                                                                 │
│ ❱ 1031 │   │   │   │   │   │   output = orig_forward(*args, **kwargs)                            │
│   1032 │   │   │   │   │   if not isinstance(output, tuple):                                     │
│   1033 │   │   │   │   │   │   collected_outputs[key] += (output,)                               │
│   1034 │   │   │   │   │   elif output[index] is not None:                                       │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/utils/deprecation.py:172 in   │
│ wrapped_func                                                                                     │
│                                                                                                  │
│   169 │   │   │   │   # DeprecationWarning is ignored by default, so we use FutureWarning inst   │
│   170 │   │   │   │   warnings.warn(message, FutureWarning, stacklevel=2)                        │
│   171 │   │   │                                                                                  │
│ ❱ 172 │   │   │   return func(*args, **kwargs)                                                   │
│   173 │   │                                                                                      │
│   174 │   │   return wrapped_func                                                                │
│   175                                                                                            │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/models/gpt_oss/modeling_gpt_o │
│ ss.py:371 in forward                                                                             │
│                                                                                                  │
│   368 │   │   residual = hidden_states                                                           │
│   369 │   │   hidden_states = self.input_layernorm(hidden_states)                                │
│   370 │   │   # Self Attention                                                                   │
│ ❱ 371 │   │   hidden_states, _ = self.self_attn(                                                 │
│   372 │   │   │   hidden_states=hidden_states,                                                   │
│   373 │   │   │   attention_mask=attention_mask,                                                 │
│   374 │   │   │   position_ids=position_ids,                                                     │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/torch/nn/modules/module.py:1779 in         │
│ _wrapped_call_impl                                                                               │
│                                                                                                  │
│   1776 │   │   if self._compiled_call_impl is not None:                                          │
│   1777 │   │   │   return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]        │
│   1778 │   │   else:                                                                             │
│ ❱ 1779 │   │   │   return self._call_impl(*args, **kwargs)                                       │
│   1780 │                                                                                         │
│   1781 │   # torchrec tests the code consistency with the following code                         │
│   1782 │   # fmt: off                                                                            │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/torch/nn/modules/module.py:1790 in         │
│ _call_impl                                                                                       │
│                                                                                                  │
│   1787 │   │   if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks   │
│   1788 │   │   │   │   or _global_backward_pre_hooks or _global_backward_hooks                   │
│   1789 │   │   │   │   or _global_forward_hooks or _global_forward_pre_hooks):                   │
│ ❱ 1790 │   │   │   return forward_call(*args, **kwargs)                                          │
│   1791 │   │                                                                                     │
│   1792 │   │   result = None                                                                     │
│   1793 │   │   called_always_called_hooks = set()                                                │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/utils/deprecation.py:172 in   │
│ wrapped_func                                                                                     │
│                                                                                                  │
│   169 │   │   │   │   # DeprecationWarning is ignored by default, so we use FutureWarning inst   │
│   170 │   │   │   │   warnings.warn(message, FutureWarning, stacklevel=2)                        │
│   171 │   │   │                                                                                  │
│ ❱ 172 │   │   │   return func(*args, **kwargs)                                                   │
│   173 │   │                                                                                      │
│   174 │   │   return wrapped_func                                                                │
│   175                                                                                            │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/models/gpt_oss/modeling_gpt_o │
│ ss.py:328 in forward                                                                             │
│                                                                                                  │
│   325 │   │   if self.config._attn_implementation != "eager":                                    │
│   326 │   │   │   attention_interface = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementati   │
│   327 │   │                                                                                      │
│ ❱ 328 │   │   attn_output, attn_weights = attention_interface(                                   │
│   329 │   │   │   self,                                                                          │
│   330 │   │   │   query_states,                                                                  │
│   331 │   │   │   key_states,                                                                    │
│                                                                                                  │
│ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/models/gpt_oss/modeling_gpt_o │
│ ss.py:264 in eager_attention_forward                                                             │
│                                                                                                  │
│   261 │   # This was not in the original implementation and slightly affect results; it preven   │
│   262 │   # when training with bsz>1 we clamp max values.                                        │
│   263 │                                                                                          │
│ ❱ 264 │   combined_logits = combined_logits - combined_logits.max(dim=-1, keepdim=True).values   │
│   265 │   probs = F.softmax(combined_logits, dim=-1, dtype=combined_logits.dtype)                │
│   266 │   scores = probs[..., :-1]  # we drop the sink here                                      │
│   267 │   attn_weights = nn.functional.dropout(scores, p=dropout, training=module.training)      │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
OutOfMemoryError: CUDA out of memory. Tried to allocate 132.00 MiB. GPU 0 has a total capacity of 23.52 GiB of which 76.19 MiB is free. Process 1747 has 2.97 GiB memory in use. Process 1619 
has 1.10 GiB memory in use. Process 30526 has 526.00 MiB memory in use. Process 36991 has 860.00 MiB memory in use. Process 36960 has 1.17 GiB memory in use. Process 38806 has 423.94 MiB 
memory in use. Process 38800 has 423.94 MiB memory in use. Including non-PyTorch memory, this process has 15.98 GiB memory in use. Of the allocated memory 14.87 GiB is allocated by PyTorch, 
and 669.88 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation.  See 
documentation for Memory Management  (https://docs.pytorch.org/docs/stable/notes/cuda.html#optimizing-memory-usage-with-pytorch-cuda-alloc-conf)

I'll git bissect later today

<!-- gh-comment-id:4133998960 --> @mightykatun commented on GitHub (Mar 26, 2026): Hi, I am encountering the same issue with openai/gpt-oss-120b with an RXT4090, getting almost the same output with or without the --max-memory flag. Fails too with a smaller model (tried openai/gpt-oss-20b), but later. I don't know it it's a requirement to be able to fit the entire model in the gpu? <details> <summary>Log for openai/gpt-oss-120b</summary> ``` heretic --model openai/gpt-oss-120b --max-memory '{"0": "16GB", "cpu": "100GB"}' █░█░█▀▀░█▀▄░█▀▀░▀█▀░█░█▀▀ v1.2.0 █▀█░█▀▀░█▀▄░█▀▀░░█░░█░█░░ ▀░▀░▀▀▀░▀░▀░▀▀▀░░▀░░▀░▀▀▀ https://github.com/p-e-w/heretic Detected 1 CUDA device(s): * GPU 0: NVIDIA GeForce RTX 4090 Loading model openai/gpt-oss-120b... Fetching 41 files: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 41/41 [00:00<00:00, 191073.85it/s] Fetching 41 files: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 41/41 [00:00<00:00, 5942.17it/s] Loading checkpoint shards: 27%|█████████████████████████████████▊ | 4/15 [00:01<00:04, 2.22it/s] Failed (CUDA out of memory. Tried to allocate 1014.00 MiB. GPU 0 has a total capacity of 23.52 GiB of which 29.06 MiB is free. Process 1747 has 2.97 GiB memory in use. Process 1619 has 1.10 GiB memory in use. Including non-PyTorch memory, this process has 19.40 GiB memory in use. Of the allocated memory 18.97 GiB is allocated by PyTorch, and 47.62 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation. See documentation for Memory Management (https://docs.pytorch.org/docs/stable/notes/cuda.html#optimizing-memory-usage-with-pytorch-cuda-alloc-conf)) Fetching 41 files: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 41/41 [00:00<00:00, 10595.59it/s] Fetching 41 files: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 41/41 [00:00<00:00, 4380.53it/s] Loading checkpoint shards: 0%| | 0/15 [00:00<?, ?it/s] Failed (CUDA out of memory. Tried to allocate 508.00 MiB. GPU 0 has a total capacity of 23.52 GiB of which 97.06 MiB is free. Process 1747 has 2.97 GiB memory in use. Process 1619 has 1.10 GiB memory in use. Including non-PyTorch memory, this process has 19.33 GiB memory in use. Of the allocated memory 18.92 GiB is allocated by PyTorch, and 30.28 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation. See documentation for Memory Management (https://docs.pytorch.org/docs/stable/notes/cuda.html#optimizing-memory-usage-with-pytorch-cuda-alloc-conf)) Fetching 41 files: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 41/41 [00:00<00:00, 10088.97it/s] Fetching 41 files: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 41/41 [00:00<00:00, 5208.74it/s] Loading checkpoint shards: 27%|█████████████████████████████████▊ | 4/15 [00:01<00:04, 2.23it/s] Failed (CUDA out of memory. Tried to allocate 1014.00 MiB. GPU 0 has a total capacity of 23.52 GiB of which 29.06 MiB is free. Process 1747 has 2.97 GiB memory in use. Process 1619 has 1.10 GiB memory in use. Including non-PyTorch memory, this process has 19.40 GiB memory in use. Of the allocated memory 18.97 GiB is allocated by PyTorch, and 47.62 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation. See documentation for Memory Management (https://docs.pytorch.org/docs/stable/notes/cuda.html#optimizing-memory-usage-with-pytorch-cuda-alloc-conf)) Fetching 41 files: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 41/41 [00:00<00:00, 8755.93it/s] Fetching 41 files: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 41/41 [00:00<00:00, 17034.82it/s] Loading checkpoint shards: 0%| | 0/15 [00:00<?, ?it/s] Failed (CUDA out of memory. Tried to allocate 508.00 MiB. GPU 0 has a total capacity of 23.52 GiB of which 97.06 MiB is free. Process 1747 has 2.97 GiB memory in use. Process 1619 has 1.10 GiB memory in use. Including non-PyTorch memory, this process has 19.33 GiB memory in use. Of the allocated memory 18.92 GiB is allocated by PyTorch, and 30.28 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation. See documentation for Memory Management (https://docs.pytorch.org/docs/stable/notes/cuda.html#optimizing-memory-usage-with-pytorch-cuda-alloc-conf)) ╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │ /home/user/heretic/.venv/bin/heretic:7 in <module> │ │ │ │ 4 if __name__ == '__main__': │ │ 5 │ if sys.argv[0].endswith('.exe'): │ │ 6 │ │ sys.argv[0] = sys.argv[0][:-4] │ │ ❱ 7 │ sys.exit(main()) │ │ 8 │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/heretic/main.py:891 in main │ │ │ │ 888 │ install() │ │ 889 │ │ │ 890 │ try: │ │ ❱ 891 │ │ run() │ │ 892 │ except BaseException as error: │ │ 893 │ │ # Transformers appears to handle KeyboardInterrupt (or BaseException) │ │ 894 │ │ # internally in some places, which can re-raise a different error in the handler │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/heretic/main.py:312 in run │ │ │ │ 309 │ │ elif choice is None or choice == "": │ │ 310 │ │ │ return │ │ 311 │ │ │ ❱ 312 │ model = Model(settings) │ │ 313 │ print() │ │ 314 │ print_memory_usage() │ │ 315 │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/heretic/model.py:145 in __init__ │ │ │ │ 142 │ │ │ break │ │ 143 │ │ │ │ 144 │ │ if self.model is None: │ │ ❱ 145 │ │ │ raise Exception("Failed to load model with all configured dtypes.") │ │ 146 │ │ │ │ 147 │ │ self._apply_lora() │ │ 148 │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ Exception: Failed to load model with all configured dtypes. ``` </details> <details> <summary>Log for openai/gpt-oss-20b</summary> ``` heretic --model openai/gpt-oss-20b █░█░█▀▀░█▀▄░█▀▀░▀█▀░█░█▀▀ v1.2.0 █▀█░█▀▀░█▀▄░█▀▀░░█░░█░█░░ ▀░▀░▀▀▀░▀░▀░▀▀▀░░▀░░▀░▀▀▀ https://github.com/p-e-w/heretic Detected 1 CUDA device(s): * GPU 0: NVIDIA GeForce RTX 4090 Loading model openai/gpt-oss-20b... Fetching 41 files: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 41/41 [00:00<00:00, 271668.98it/s] Fetching 41 files: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 41/41 [00:00<00:00, 23762.12it/s] Loading checkpoint shards: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:01<00:00, 2.00it/s] Ok * LoRA adapters initialized (targets: o_proj) * Transformer model with 24 layers * Abliterable components: * attn.o_proj: 1 modules per layer Resident system RAM: 1.66 GB Allocated GPU VRAM: 12.84 GB Reserved GPU VRAM: 12.92 GB Loading good prompts from mlabonne/harmless_alpaca... * 400 prompts loaded Loading bad prompts from mlabonne/harmful_behaviors... * 400 prompts loaded Determining optimal batch size... * Trying batch size 1... Ok (30 tokens/s) * Trying batch size 2... Ok (59 tokens/s) * Trying batch size 4... Ok (116 tokens/s) * Trying batch size 8... Ok (231 tokens/s) * Trying batch size 16... Ok (453 tokens/s) * Trying batch size 32... Ok (808 tokens/s) * Trying batch size 64... Ok (1426 tokens/s) * Trying batch size 128... Failed (CUDA out of memory. Tried to allocate 228.00 MiB. GPU 0 has a total capacity of 23.52 GiB of which 76.19 MiB is free. Process 1747 has 2.97 GiB memory in use. Process 1619 has 1.10 GiB memory in use. Process 30526 has 526.00 MiB memory in use. Process 36991 has 860.00 MiB memory in use. Process 36960 has 1.17 GiB memory in use. Process 38806 has 423.94 MiB memory in use. Process 38800 has 423.94 MiB memory in use. Including non-PyTorch memory, this process has 15.98 GiB memory in use. Of the allocated memory 14.54 GiB is allocated by PyTorch, and 1009.46 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation. See documentation for Memory Management (https://docs.pytorch.org/docs/stable/notes/cuda.html#optimizing-memory-usage-with-pytorch-cuda-alloc-conf)) * Chosen batch size: 64 Checking for common response prefix... * Prefix found: '<|channel|>analysis<|message|><|end|><|start|>assistant<|channel|>final<|message|>' Loading good evaluation prompts from mlabonne/harmless_alpaca... * 100 prompts loaded * Obtaining first-token probability distributions... Loading bad evaluation prompts from mlabonne/harmful_behaviors... * 100 prompts loaded * Counting model refusals... * Initial refusals: 98/100 Calculating per-layer refusal directions... * Obtaining residuals for good prompts... ╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │ /home/user/heretic/.venv/bin/heretic:7 in <module> │ │ │ │ 4 if __name__ == '__main__': │ │ 5 │ if sys.argv[0].endswith('.exe'): │ │ 6 │ │ sys.argv[0] = sys.argv[0][:-4] │ │ ❱ 7 │ sys.exit(main()) │ │ 8 │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/heretic/main.py:891 in main │ │ │ │ 888 │ install() │ │ 889 │ │ │ 890 │ try: │ │ ❱ 891 │ │ run() │ │ 892 │ except BaseException as error: │ │ 893 │ │ # Transformers appears to handle KeyboardInterrupt (or BaseException) │ │ 894 │ │ # internally in some places, which can re-raise a different error in the handler │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/heretic/main.py:417 in run │ │ │ │ 414 │ print() │ │ 415 │ print("Calculating per-layer refusal directions...") │ │ 416 │ print("* Obtaining residuals for good prompts...") │ │ ❱ 417 │ good_residuals = model.get_residuals_batched(good_prompts) │ │ 418 │ print("* Obtaining residuals for bad prompts...") │ │ 419 │ bad_residuals = model.get_residuals_batched(bad_prompts) │ │ 420 │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/heretic/model.py:652 in │ │ get_residuals_batched │ │ │ │ 649 │ │ residuals = [] │ │ 650 │ │ │ │ 651 │ │ for batch in batchify(prompts, self.settings.batch_size): │ │ ❱ 652 │ │ │ residuals.append(self.get_residuals(batch)) │ │ 653 │ │ │ │ 654 │ │ return torch.cat(residuals, dim=0) │ │ 655 │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/heretic/model.py:606 in get_residuals │ │ │ │ 603 │ def get_residuals(self, prompts: list[Prompt]) -> Tensor: │ │ 604 │ │ # We only generate one token, and we return the residual vectors │ │ 605 │ │ # at that token position, for each prompt and layer. │ │ ❱ 606 │ │ _, outputs = self.generate( │ │ 607 │ │ │ prompts, │ │ 608 │ │ │ max_new_tokens=1, │ │ 609 │ │ │ output_hidden_states=True, │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/heretic/model.py:560 in generate │ │ │ │ 557 │ │ │ │ 558 │ │ # FIXME: The type checker has been disabled here because of the extremely comple │ │ 559 │ │ # interplay between different generate() signatures and dynamic delegatio │ │ ❱ 560 │ │ outputs = self.model.generate( │ │ 561 │ │ │ **inputs, │ │ 562 │ │ │ **kwargs, │ │ 563 │ │ │ pad_token_id=self.tokenizer.pad_token_id, │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/peft/peft_model.py:2048 in generate │ │ │ │ 2045 │ │ │ │ kwargs = get_alora_offsets_for_generate(self, *args, **kwargs) │ │ 2046 │ │ │ │ with self._enable_peft_forward_hooks(*args, **kwargs): │ │ 2047 │ │ │ │ │ kwargs = {k: v for k, v in kwargs.items() if k not in self.special_p │ │ ❱ 2048 │ │ │ │ │ outputs = self.base_model.generate(*args, **kwargs) │ │ 2049 │ │ │ else: │ │ 2050 │ │ │ │ outputs = self.base_model.generate(**kwargs) │ │ 2051 │ │ except: │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/torch/utils/_contextlib.py:124 in │ │ decorate_context │ │ │ │ 121 │ def decorate_context(*args, **kwargs): │ │ 122 │ │ # pyrefly: ignore [bad-context-manager] │ │ 123 │ │ with ctx_factory(): │ │ ❱ 124 │ │ │ return func(*args, **kwargs) │ │ 125 │ │ │ 126 │ return decorate_context │ │ 127 │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/generation/utils.py:2566 in │ │ generate │ │ │ │ 2563 │ │ model_kwargs["use_cache"] = generation_config.use_cache │ │ 2564 │ │ │ │ 2565 │ │ # 9. Call generation mode │ │ ❱ 2566 │ │ result = decoding_method( │ │ 2567 │ │ │ self, │ │ 2568 │ │ │ input_ids, │ │ 2569 │ │ │ logits_processor=prepared_logits_processor, │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/generation/utils.py:2786 in │ │ _sample │ │ │ │ 2783 │ │ │ model_inputs = self.prepare_inputs_for_generation(input_ids, **model_kwargs) │ │ 2784 │ │ │ │ │ 2785 │ │ │ if is_prefill: │ │ ❱ 2786 │ │ │ │ outputs = self(**model_inputs, return_dict=True) │ │ 2787 │ │ │ │ is_prefill = False │ │ 2788 │ │ │ else: │ │ 2789 │ │ │ │ outputs = model_forward(**model_inputs, return_dict=True) │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/torch/nn/modules/module.py:1779 in │ │ _wrapped_call_impl │ │ │ │ 1776 │ │ if self._compiled_call_impl is not None: │ │ 1777 │ │ │ return self._compiled_call_impl(*args, **kwargs) # type: ignore[misc] │ │ 1778 │ │ else: │ │ ❱ 1779 │ │ │ return self._call_impl(*args, **kwargs) │ │ 1780 │ │ │ 1781 │ # torchrec tests the code consistency with the following code │ │ 1782 │ # fmt: off │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/torch/nn/modules/module.py:1790 in │ │ _call_impl │ │ │ │ 1787 │ │ if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks │ │ 1788 │ │ │ │ or _global_backward_pre_hooks or _global_backward_hooks │ │ 1789 │ │ │ │ or _global_forward_hooks or _global_forward_pre_hooks): │ │ ❱ 1790 │ │ │ return forward_call(*args, **kwargs) │ │ 1791 │ │ │ │ 1792 │ │ result = None │ │ 1793 │ │ called_always_called_hooks = set() │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/utils/generic.py:918 in │ │ wrapper │ │ │ │ 915 │ │ return_dict_passed = kwargs.pop("return_dict", return_dict) │ │ 916 │ │ if return_dict_passed is not None: │ │ 917 │ │ │ return_dict = return_dict_passed │ │ ❱ 918 │ │ output = func(self, *args, **kwargs) │ │ 919 │ │ if not return_dict and not isinstance(output, tuple): │ │ 920 │ │ │ output = output.to_tuple() │ │ 921 │ │ return output │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/models/gpt_oss/modeling_gpt_o │ │ ss.py:668 in forward │ │ │ │ 665 │ │ ) │ │ 666 │ │ │ │ 667 │ │ # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn) │ │ ❱ 668 │ │ outputs: MoeModelOutputWithPast = self.model( │ │ 669 │ │ │ input_ids=input_ids, │ │ 670 │ │ │ attention_mask=attention_mask, │ │ 671 │ │ │ position_ids=position_ids, │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/torch/nn/modules/module.py:1779 in │ │ _wrapped_call_impl │ │ │ │ 1776 │ │ if self._compiled_call_impl is not None: │ │ 1777 │ │ │ return self._compiled_call_impl(*args, **kwargs) # type: ignore[misc] │ │ 1778 │ │ else: │ │ ❱ 1779 │ │ │ return self._call_impl(*args, **kwargs) │ │ 1780 │ │ │ 1781 │ # torchrec tests the code consistency with the following code │ │ 1782 │ # fmt: off │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/torch/nn/modules/module.py:1790 in │ │ _call_impl │ │ │ │ 1787 │ │ if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks │ │ 1788 │ │ │ │ or _global_backward_pre_hooks or _global_backward_hooks │ │ 1789 │ │ │ │ or _global_forward_hooks or _global_forward_pre_hooks): │ │ ❱ 1790 │ │ │ return forward_call(*args, **kwargs) │ │ 1791 │ │ │ │ 1792 │ │ result = None │ │ 1793 │ │ called_always_called_hooks = set() │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/utils/generic.py:1072 in │ │ wrapper │ │ │ │ 1069 │ │ │ │ │ │ │ monkey_patched_layers.append((module, original_forward)) │ │ 1070 │ │ │ │ │ 1071 │ │ │ try: │ │ ❱ 1072 │ │ │ │ outputs = func(self, *args, **kwargs) │ │ 1073 │ │ │ except TypeError as original_exception: │ │ 1074 │ │ │ │ # If we get a TypeError, it's possible that the model is not receiving t │ │ 1075 │ │ │ │ # Get a TypeError even after removing the recordable kwargs -> re-raise │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/models/gpt_oss/modeling_gpt_o │ │ ss.py:507 in forward │ │ │ │ 504 │ │ position_embeddings = self.rotary_emb(hidden_states, position_ids) │ │ 505 │ │ │ │ 506 │ │ for decoder_layer in self.layers: │ │ ❱ 507 │ │ │ hidden_states = decoder_layer( │ │ 508 │ │ │ │ hidden_states, │ │ 509 │ │ │ │ attention_mask=causal_mask_mapping[decoder_layer.attention_type], │ │ 510 │ │ │ │ position_ids=position_ids, │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/modeling_layers.py:94 in │ │ __call__ │ │ │ │ 91 │ │ │ │ logger.warning_once(message) │ │ 92 │ │ │ │ │ 93 │ │ │ return self._gradient_checkpointing_func(partial(super().__call__, **kwargs) │ │ ❱ 94 │ │ return super().__call__(*args, **kwargs) │ │ 95 │ │ 96 │ │ 97 @auto_docstring │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/torch/nn/modules/module.py:1779 in │ │ _wrapped_call_impl │ │ │ │ 1776 │ │ if self._compiled_call_impl is not None: │ │ 1777 │ │ │ return self._compiled_call_impl(*args, **kwargs) # type: ignore[misc] │ │ 1778 │ │ else: │ │ ❱ 1779 │ │ │ return self._call_impl(*args, **kwargs) │ │ 1780 │ │ │ 1781 │ # torchrec tests the code consistency with the following code │ │ 1782 │ # fmt: off │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/torch/nn/modules/module.py:1790 in │ │ _call_impl │ │ │ │ 1787 │ │ if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks │ │ 1788 │ │ │ │ or _global_backward_pre_hooks or _global_backward_hooks │ │ 1789 │ │ │ │ or _global_forward_hooks or _global_forward_pre_hooks): │ │ ❱ 1790 │ │ │ return forward_call(*args, **kwargs) │ │ 1791 │ │ │ │ 1792 │ │ result = None │ │ 1793 │ │ called_always_called_hooks = set() │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/utils/generic.py:1031 in │ │ wrapped_forward │ │ │ │ 1028 │ │ │ │ │ │ ): │ │ 1029 │ │ │ │ │ │ │ output = orig_forward(*args, **kwargs) │ │ 1030 │ │ │ │ │ else: │ │ ❱ 1031 │ │ │ │ │ │ output = orig_forward(*args, **kwargs) │ │ 1032 │ │ │ │ │ if not isinstance(output, tuple): │ │ 1033 │ │ │ │ │ │ collected_outputs[key] += (output,) │ │ 1034 │ │ │ │ │ elif output[index] is not None: │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/utils/deprecation.py:172 in │ │ wrapped_func │ │ │ │ 169 │ │ │ │ # DeprecationWarning is ignored by default, so we use FutureWarning inst │ │ 170 │ │ │ │ warnings.warn(message, FutureWarning, stacklevel=2) │ │ 171 │ │ │ │ │ ❱ 172 │ │ │ return func(*args, **kwargs) │ │ 173 │ │ │ │ 174 │ │ return wrapped_func │ │ 175 │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/models/gpt_oss/modeling_gpt_o │ │ ss.py:371 in forward │ │ │ │ 368 │ │ residual = hidden_states │ │ 369 │ │ hidden_states = self.input_layernorm(hidden_states) │ │ 370 │ │ # Self Attention │ │ ❱ 371 │ │ hidden_states, _ = self.self_attn( │ │ 372 │ │ │ hidden_states=hidden_states, │ │ 373 │ │ │ attention_mask=attention_mask, │ │ 374 │ │ │ position_ids=position_ids, │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/torch/nn/modules/module.py:1779 in │ │ _wrapped_call_impl │ │ │ │ 1776 │ │ if self._compiled_call_impl is not None: │ │ 1777 │ │ │ return self._compiled_call_impl(*args, **kwargs) # type: ignore[misc] │ │ 1778 │ │ else: │ │ ❱ 1779 │ │ │ return self._call_impl(*args, **kwargs) │ │ 1780 │ │ │ 1781 │ # torchrec tests the code consistency with the following code │ │ 1782 │ # fmt: off │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/torch/nn/modules/module.py:1790 in │ │ _call_impl │ │ │ │ 1787 │ │ if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks │ │ 1788 │ │ │ │ or _global_backward_pre_hooks or _global_backward_hooks │ │ 1789 │ │ │ │ or _global_forward_hooks or _global_forward_pre_hooks): │ │ ❱ 1790 │ │ │ return forward_call(*args, **kwargs) │ │ 1791 │ │ │ │ 1792 │ │ result = None │ │ 1793 │ │ called_always_called_hooks = set() │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/utils/deprecation.py:172 in │ │ wrapped_func │ │ │ │ 169 │ │ │ │ # DeprecationWarning is ignored by default, so we use FutureWarning inst │ │ 170 │ │ │ │ warnings.warn(message, FutureWarning, stacklevel=2) │ │ 171 │ │ │ │ │ ❱ 172 │ │ │ return func(*args, **kwargs) │ │ 173 │ │ │ │ 174 │ │ return wrapped_func │ │ 175 │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/models/gpt_oss/modeling_gpt_o │ │ ss.py:328 in forward │ │ │ │ 325 │ │ if self.config._attn_implementation != "eager": │ │ 326 │ │ │ attention_interface = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementati │ │ 327 │ │ │ │ ❱ 328 │ │ attn_output, attn_weights = attention_interface( │ │ 329 │ │ │ self, │ │ 330 │ │ │ query_states, │ │ 331 │ │ │ key_states, │ │ │ │ /home/user/heretic/.venv/lib/python3.14/site-packages/transformers/models/gpt_oss/modeling_gpt_o │ │ ss.py:264 in eager_attention_forward │ │ │ │ 261 │ # This was not in the original implementation and slightly affect results; it preven │ │ 262 │ # when training with bsz>1 we clamp max values. │ │ 263 │ │ │ ❱ 264 │ combined_logits = combined_logits - combined_logits.max(dim=-1, keepdim=True).values │ │ 265 │ probs = F.softmax(combined_logits, dim=-1, dtype=combined_logits.dtype) │ │ 266 │ scores = probs[..., :-1] # we drop the sink here │ │ 267 │ attn_weights = nn.functional.dropout(scores, p=dropout, training=module.training) │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ OutOfMemoryError: CUDA out of memory. Tried to allocate 132.00 MiB. GPU 0 has a total capacity of 23.52 GiB of which 76.19 MiB is free. Process 1747 has 2.97 GiB memory in use. Process 1619 has 1.10 GiB memory in use. Process 30526 has 526.00 MiB memory in use. Process 36991 has 860.00 MiB memory in use. Process 36960 has 1.17 GiB memory in use. Process 38806 has 423.94 MiB memory in use. Process 38800 has 423.94 MiB memory in use. Including non-PyTorch memory, this process has 15.98 GiB memory in use. Of the allocated memory 14.87 GiB is allocated by PyTorch, and 669.88 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation. See documentation for Memory Management (https://docs.pytorch.org/docs/stable/notes/cuda.html#optimizing-memory-usage-with-pytorch-cuda-alloc-conf) ``` </details> I'll git bissect later today
Author
Owner

@p-e-w commented on GitHub (Mar 27, 2026):

See #239.

<!-- gh-comment-id:4141839465 --> @p-e-w commented on GitHub (Mar 27, 2026): See #239.
Author
Owner

@mightykatun commented on GitHub (Mar 27, 2026):

Thanks! I'll take a look at it once it's merged and update you on if it fixes the issue :)

<!-- gh-comment-id:4141960013 --> @mightykatun commented on GitHub (Mar 27, 2026): Thanks! I'll take a look at it once it's merged and update you on if it fixes the issue :)
Author
Owner

@p-e-w commented on GitHub (Jun 16, 2026):

This should be fixed in #239.

<!-- gh-comment-id:4716259785 --> @p-e-w commented on GitHub (Jun 16, 2026): This should be fixed in #239.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
p-e-w/heretic#51
No description provided.