[GH-ISSUE #949] [Bug] RuntimeError: CUDA error: invalid device function #674

Open
opened 2026-10-29 14:42:43 +00:00 by bsakaguchi · 1 comment
Owner

Originally created by @Z27-DSR1 on GitHub (Mar 21, 2025).
Original GitHub issue: https://github.com/kvcache-ai/ktransformers/issues/949

Originally assigned to: @Atream on GitHub.

检查清单

  • 1. 我已经搜索过相关问题,但未能获得预期的帮助
  • 2. 该问题在最新版本中尚未修复
  • 3. 请注意,如果您提交的BUG相关 issue 缺少对应环境信息和最小可复现示例,我们将难以复现和定位问题,降低获得反馈的可能性
  • 4. 如果您提出的不是bug而是问题,请在讨论区发起讨论 https://github.com/kvcache-ai/ktransformers/discussions。否则该 issue 将被关闭
  • 5. 为方便社区交流,我将使用中文/英文或附上中文/英文翻译(如使用其他语言)。未附带翻译的非中文/英语内容可能会被关闭

问题描述

运行 python ./ktransformers/local_chat.py --model_path /home/zdsr1/DeepSeek-R1 --gguf_path /home/zdsr1/DeepSeek-R1-GGUF/DeepSeek-R1-UD-IQ1_S --cpu_infer 56 --max_new_tokens 512 --force_think true 成功加载完成后,在Chat:对话过程中,出现如下错误,

Chat: 你好,你是谁?
Traceback (most recent call last):
File "/home/zdsr1/ktransformers/./ktransformers/local_chat.py", line 185, in
fire.Fire(local_chat)
File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/fire/core.py", line 135, in Fire
component_trace = _Fire(component, args, parsed_flag_args, context, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/fire/core.py", line 468, in _Fire
component, remaining_args = _CallAndUpdateTrace(
^^^^^^^^^^^^^^^^^^^^
File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/fire/core.py", line 684, in _CallAndUpdateTrace
component = fn(*varargs, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/zdsr1/ktransformers/./ktransformers/local_chat.py", line 179, in local_chat
generated = prefill_and_generate(
^^^^^^^^^^^^^^^^^^^^^
File "/home/zdsr1/ktransformers/./ktransformers/util/utils.py", line 208, in prefill_and_generate
logits = chunk_prefill(inputs[:, chunk_start:chunk_end], cache_position[chunk_start:chunk_end], past_key_values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/zdsr1/ktransformers/./ktransformers/util/utils.py", line 165, in chunk_prefill
logits = model(
^^^^^^
File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/zdsr1/ktransformers/./ktransformers/models/modeling_deepseek_v3.py", line 1688, in forward
outputs = self.model(
^^^^^^^^^^^
File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/zdsr1/ktransformers/./ktransformers/operators/models.py", line 729, in forward
layer_outputs = decoder_layer(
^^^^^^^^^^^^^^
File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/zdsr1/ktransformers/./ktransformers/models/modeling_deepseek_v3.py", line 1205, in forward
hidden_states, self_attn_weights, present_key_value = self.self_attn(
^^^^^^^^^^^^^^^
File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/zdsr1/ktransformers/./ktransformers/operators/attention.py", line 599, in forward
return self.forward_windows(
^^^^^^^^^^^^^^^^^^^^^
File "/home/zdsr1/ktransformers/./ktransformers/operators/attention.py", line 539, in forward_windows
return self.forward_chunck(
^^^^^^^^^^^^^^^^^^^^
File "/home/zdsr1/ktransformers/./ktransformers/operators/attention.py", line 90, in forward_chunck
q = self.q_b_proj(self.q_a_layernorm(self.q_a_proj(hidden_states)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/zdsr1/ktransformers/./ktransformers/models/modeling_deepseek_v3.py", line 105, in forward
hidden_states = hidden_states.to(torch.float32)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: CUDA error: invalid device function
CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1
Compile with TORCH_USE_CUDA_DSA to enable device-side assertions.

请问如何解决这个问题。

复现步骤

python ./ktransformers/local_chat.py --model_path /home/zdsr1/DeepSeek-R1 --gguf_path /home/zdsr1/DeepSeek-R1-GGUF/DeepSeek-R1-UD-IQ1_S --cpu_infer 56 --max_new_tokens 512 --force_think true

环境信息

Win10 WSL2 Ubuntu22.04
双路Xeon Platinu 8260/767G内存/Nvidia Quadro RTX5000 16G显存
CUDA12.4/Pytorch2.5/Python311

Originally created by @Z27-DSR1 on GitHub (Mar 21, 2025). Original GitHub issue: https://github.com/kvcache-ai/ktransformers/issues/949 Originally assigned to: @Atream on GitHub. ### 检查清单 - [ ] 1. 我已经搜索过相关问题,但未能获得预期的帮助 - [ ] 2. 该问题在最新版本中尚未修复 - [ ] 3. 请注意,如果您提交的BUG相关 issue 缺少对应环境信息和最小可复现示例,我们将难以复现和定位问题,降低获得反馈的可能性 - [ ] 4. 如果您提出的不是bug而是问题,请在讨论区发起讨论 https://github.com/kvcache-ai/ktransformers/discussions。否则该 issue 将被关闭 - [ ] 5. 为方便社区交流,我将使用中文/英文或附上中文/英文翻译(如使用其他语言)。未附带翻译的非中文/英语内容可能会被关闭 ### 问题描述 运行 python ./ktransformers/local_chat.py --model_path /home/zdsr1/DeepSeek-R1 --gguf_path /home/zdsr1/DeepSeek-R1-GGUF/DeepSeek-R1-UD-IQ1_S --cpu_infer 56 --max_new_tokens 512 --force_think true 成功加载完成后,在Chat:对话过程中,出现如下错误, Chat: 你好,你是谁? Traceback (most recent call last): File "/home/zdsr1/ktransformers/./ktransformers/local_chat.py", line 185, in <module> fire.Fire(local_chat) File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/fire/core.py", line 135, in Fire component_trace = _Fire(component, args, parsed_flag_args, context, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/fire/core.py", line 468, in _Fire component, remaining_args = _CallAndUpdateTrace( ^^^^^^^^^^^^^^^^^^^^ File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/fire/core.py", line 684, in _CallAndUpdateTrace component = fn(*varargs, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^ File "/home/zdsr1/ktransformers/./ktransformers/local_chat.py", line 179, in local_chat generated = prefill_and_generate( ^^^^^^^^^^^^^^^^^^^^^ File "/home/zdsr1/ktransformers/./ktransformers/util/utils.py", line 208, in prefill_and_generate logits = chunk_prefill(inputs[:, chunk_start:chunk_end], cache_position[chunk_start:chunk_end], past_key_values) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/zdsr1/ktransformers/./ktransformers/util/utils.py", line 165, in chunk_prefill logits = model( ^^^^^^ File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/zdsr1/ktransformers/./ktransformers/models/modeling_deepseek_v3.py", line 1688, in forward outputs = self.model( ^^^^^^^^^^^ File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/zdsr1/ktransformers/./ktransformers/operators/models.py", line 729, in forward layer_outputs = decoder_layer( ^^^^^^^^^^^^^^ File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/zdsr1/ktransformers/./ktransformers/models/modeling_deepseek_v3.py", line 1205, in forward hidden_states, self_attn_weights, present_key_value = self.self_attn( ^^^^^^^^^^^^^^^ File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/zdsr1/ktransformers/./ktransformers/operators/attention.py", line 599, in forward return self.forward_windows( ^^^^^^^^^^^^^^^^^^^^^ File "/home/zdsr1/ktransformers/./ktransformers/operators/attention.py", line 539, in forward_windows return self.forward_chunck( ^^^^^^^^^^^^^^^^^^^^ File "/home/zdsr1/ktransformers/./ktransformers/operators/attention.py", line 90, in forward_chunck q = self.q_b_proj(self.q_a_layernorm(self.q_a_proj(hidden_states))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/zdsr1/anaconda3/envs/kt/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/zdsr1/ktransformers/./ktransformers/models/modeling_deepseek_v3.py", line 105, in forward hidden_states = hidden_states.to(torch.float32) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RuntimeError: CUDA error: invalid device function CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect. For debugging consider passing CUDA_LAUNCH_BLOCKING=1 Compile with `TORCH_USE_CUDA_DSA` to enable device-side assertions. 请问如何解决这个问题。 ### 复现步骤 python ./ktransformers/local_chat.py --model_path /home/zdsr1/DeepSeek-R1 --gguf_path /home/zdsr1/DeepSeek-R1-GGUF/DeepSeek-R1-UD-IQ1_S --cpu_infer 56 --max_new_tokens 512 --force_think true ### 环境信息 Win10 WSL2 Ubuntu22.04 双路Xeon Platinu 8260/767G内存/Nvidia Quadro RTX5000 16G显存 CUDA12.4/Pytorch2.5/Python311
Author
Owner

@Atream commented on GitHub (Apr 29, 2025):

这是只有较旧的GPU会遇到的bug,目前没有统一的解决方案,之前有人通过先运行GPU版llama.cpp解决部分环境问题跑通了,但不确定是否通用。
目前我们没有ampere之前的GPU,所以暂时无法调试。

This is a bug that only older GPUs encounter. There is currently no universal solution. Previously, some people managed to resolve part of the environment issues and get it running by first executing the GPU version of llama.cpp, but it is uncertain whether this method is universally applicable.

At present, we do not have access to GPUs older than the Ampere architecture, so we are temporarily unable to debug it.

<!-- gh-comment-id:2837350175 --> @Atream commented on GitHub (Apr 29, 2025): 这是只有较旧的GPU会遇到的bug,目前没有统一的解决方案,之前有人通过先运行GPU版llama.cpp解决部分环境问题跑通了,但不确定是否通用。 目前我们没有ampere之前的GPU,所以暂时无法调试。 This is a bug that only older GPUs encounter. There is currently no universal solution. Previously, some people managed to resolve part of the environment issues and get it running by first executing the GPU version of `llama.cpp`, but it is uncertain whether this method is universally applicable. At present, we do not have access to GPUs older than the Ampere architecture, so we are temporarily unable to debug it.
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#674
No description provided.