[GH-ISSUE #683] 16G显存无法启动 #498

Closed
opened 2026-10-29 14:40:30 +00:00 by bsakaguchi · 1 comment
Owner

Originally created by @wxtt522 on GitHub (Feb 26, 2025).
Original GitHub issue: https://github.com/kvcache-ai/ktransformers/issues/683

loading blk.60.ffn_norm.weight to cuda:0
loading output_norm.weight to cuda:0
loading output.weight to cuda:0
Traceback (most recent call last):
File "/mnt/pve/h3200/model/r1/./ktransformers/ktransformers/local_chat.py", line 187, in
fire.Fire(local_chat)
File "/mnt/pve/h3200/miniconda3/envs/ktransformers/lib/python3.11/site-packages/fire/core.py", line 135, in Fire
component_trace = _Fire(component, args, parsed_flag_args, context, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/pve/h3200/miniconda3/envs/ktransformers/lib/python3.11/site-packages/fire/core.py", line 468, in _Fire
component, remaining_args = _CallAndUpdateTrace(
^^^^^^^^^^^^^^^^^^^^
File "/mnt/pve/h3200/miniconda3/envs/ktransformers/lib/python3.11/site-packages/fire/core.py", line 684, in _CallAndUpdateTrace
component = fn(*varargs, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/pve/h3200/model/r1/./ktransformers/ktransformers/local_chat.py", line 111, in local_chat
optimize_and_load_gguf(model, optimize_rule_path, gguf_path, config)
File "/mnt/pve/h3200/model/r1/./ktransformers/ktransformers/optimize/optimize.py", line 129, in optimize_and_load_gguf
load_weights(module, gguf_loader)
File "/mnt/pve/h3200/model/r1/./ktransformers/ktransformers/util/utils.py", line 86, in load_weights
load_weights(child, gguf_loader, prefix+name+".")
File "/mnt/pve/h3200/model/r1/./ktransformers/ktransformers/util/utils.py", line 84, in load_weights
load_cur_state_dict(module, gguf_loader, prefix)
File "/mnt/pve/h3200/model/r1/./ktransformers/ktransformers/util/utils.py", line 74, in load_cur_state_dict
weights = gguf_loader.load_gguf_tensor(translated_key, device = device).to(dtype = target_dtype)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 1.73 GiB. GPU 0 has a total capacity of 15.70 GiB of which 1.61 GiB is free. Including non-PyTorch memory, this process has 14.08 GiB memory in use. Of the allocated memory 13.24 GiB is allocated by PyTorch, and 725.79 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://pytorch.org/docs/stable/notes/cuda.html#environment-variables)
(ktransformers) root@pve:~/model/r1# nvidia-smi && free -g
Wed Feb 26 14:44:42 2025
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.144.03 Driver Version: 550.144.03 CUDA Version: 12.4 |
|-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 NVIDIA GeForce RTX 4060 Ti Off | 00000000:03:00.0 Off | N/A |
| 0% 30C P8 10W / 165W | 4MiB / 16380MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| No running processes found |
+-----------------------------------------------------------------------------------------+
total used free shared buff/cache available
Mem: 251 4 33 0 215 246
Swap: 0 0 0
(ktransformers) root@pve:~/model/r1# pip list|grep torch
ktransformers 0.2.1.post1+cu124torch24avx2
torch 2.4.0+cu124

看文档Q4只需要14G显存,但似乎测试都在用x090,我跑DeepSeek-R1-Q2_K_XS用256g内存ollama能跑,ktransformers跑不了吗?

Originally created by @wxtt522 on GitHub (Feb 26, 2025). Original GitHub issue: https://github.com/kvcache-ai/ktransformers/issues/683 loading blk.60.ffn_norm.weight to cuda:0 loading output_norm.weight to cuda:0 loading output.weight to cuda:0 Traceback (most recent call last): File "/mnt/pve/h3200/model/r1/./ktransformers/ktransformers/local_chat.py", line 187, in <module> fire.Fire(local_chat) File "/mnt/pve/h3200/miniconda3/envs/ktransformers/lib/python3.11/site-packages/fire/core.py", line 135, in Fire component_trace = _Fire(component, args, parsed_flag_args, context, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/pve/h3200/miniconda3/envs/ktransformers/lib/python3.11/site-packages/fire/core.py", line 468, in _Fire component, remaining_args = _CallAndUpdateTrace( ^^^^^^^^^^^^^^^^^^^^ File "/mnt/pve/h3200/miniconda3/envs/ktransformers/lib/python3.11/site-packages/fire/core.py", line 684, in _CallAndUpdateTrace component = fn(*varargs, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/pve/h3200/model/r1/./ktransformers/ktransformers/local_chat.py", line 111, in local_chat optimize_and_load_gguf(model, optimize_rule_path, gguf_path, config) File "/mnt/pve/h3200/model/r1/./ktransformers/ktransformers/optimize/optimize.py", line 129, in optimize_and_load_gguf load_weights(module, gguf_loader) File "/mnt/pve/h3200/model/r1/./ktransformers/ktransformers/util/utils.py", line 86, in load_weights load_weights(child, gguf_loader, prefix+name+".") File "/mnt/pve/h3200/model/r1/./ktransformers/ktransformers/util/utils.py", line 84, in load_weights load_cur_state_dict(module, gguf_loader, prefix) File "/mnt/pve/h3200/model/r1/./ktransformers/ktransformers/util/utils.py", line 74, in load_cur_state_dict weights = gguf_loader.load_gguf_tensor(translated_key, device = device).to(dtype = target_dtype) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 1.73 GiB. GPU 0 has a total capacity of 15.70 GiB of which 1.61 GiB is free. Including non-PyTorch memory, this process has 14.08 GiB memory in use. Of the allocated memory 13.24 GiB is allocated by PyTorch, and 725.79 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://pytorch.org/docs/stable/notes/cuda.html#environment-variables) (ktransformers) root@pve:~/model/r1# nvidia-smi && free -g Wed Feb 26 14:44:42 2025 +-----------------------------------------------------------------------------------------+ | NVIDIA-SMI 550.144.03 Driver Version: 550.144.03 CUDA Version: 12.4 | |-----------------------------------------+------------------------+----------------------+ | GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. | | | | MIG M. | |=========================================+========================+======================| | 0 NVIDIA GeForce RTX 4060 Ti Off | 00000000:03:00.0 Off | N/A | | 0% 30C P8 10W / 165W | 4MiB / 16380MiB | 0% Default | | | | N/A | +-----------------------------------------+------------------------+----------------------+ +-----------------------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=========================================================================================| | No running processes found | +-----------------------------------------------------------------------------------------+ total used free shared buff/cache available Mem: 251 4 33 0 215 246 Swap: 0 0 0 (ktransformers) root@pve:~/model/r1# pip list|grep torch ktransformers 0.2.1.post1+cu124torch24avx2 torch 2.4.0+cu124 看文档Q4只需要14G显存,但似乎测试都在用x090,我跑DeepSeek-R1-Q2_K_XS用256g内存ollama能跑,ktransformers跑不了吗?
Author
Owner

@wxtt522 commented on GitHub (Feb 26, 2025):

export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True 确实有效 Image

<!-- gh-comment-id:2684130030 --> @wxtt522 commented on GitHub (Feb 26, 2025): export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True 确实有效 ![Image](https://github.com/user-attachments/assets/bda29bbf-0a9f-4ccc-8fa6-a6b1c0318097)
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
kvcache-ai/ktransformers#498
No description provided.