[GH-ISSUE #208] RuntimeError: CUDA error: invalid device function For first message #122

Open
opened 2026-10-29 14:34:32 +00:00 by bsakaguchi · 7 comments
Owner

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

Environment

  • ktransformers: 0.2.0+cu128torch24avx2 ( git checkout v0.2.0 and compile)
  • Device: e5 2686v4 2080ti
  • torch: '2.4.0+cu121'
  • system driver: 570 with cuda 12.8
  • system cuda: 12.8

Error Log

just after first message. I got this error both with driver-cuda 12.4 and 12.8, and model unsloth q2k and q4k.

Chat: 你好
Traceback (most recent call last):
File "/home/u/prj/ktransformers/./ktransformers/local_chat.py", line 280, in
fire.Fire(local_chat)
File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/fire/core.py", line 135, in Fire
component_trace = _Fire(component, args, parsed_flag_args, context, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/fire/core.py", line 468, in _Fire
component, remaining_args = _CallAndUpdateTrace(
^^^^^^^^^^^^^^^^^^^^
File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/fire/core.py", line 684, in _CallAndUpdateTrace
component = fn(*varargs, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/u/prj/ktransformers/./ktransformers/local_chat.py", line 274, in local_chat
generated = prefill_and_generate(
^^^^^^^^^^^^^^^^^^^^^
File "/home/u/prj/ktransformers/./ktransformers/util/utils.py", line 150, in prefill_and_generate
logits = model(
^^^^^^
File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/u/prj/ktransformers/./ktransformers/models/modeling_deepseek_v3.py", line 1688, in forward
outputs = self.model(
^^^^^^^^^^^
File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/u/prj/ktransformers/./ktransformers/operators/models.py", line 722, in forward
layer_outputs = decoder_layer(
^^^^^^^^^^^^^^
File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/u/prj/ktransformers/./ktransformers/models/modeling_deepseek_v3.py", line 1205, in forward
hidden_states, self_attn_weights, present_key_value = self.self_attn(
^^^^^^^^^^^^^^^
File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/u/prj/ktransformers/./ktransformers/operators/attention.py", line 372, in forward
return self.forward_chunck(
^^^^^^^^^^^^^^^^^^^^
File "/home/u/prj/ktransformers/./ktransformers/operators/attention.py", line 273, in forward_chunck
q = self.q_b_proj(self.q_a_layernorm(self.q_a_proj(hidden_states)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/u/prj/ktransformers/./ktransformers/models/modeling_deepseek_v3.py", line 105, in forward
hidden_states = hidden_states.to(torch.float32)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: CUDA error: invalid device function

Originally created by @Xxianna on GitHub (Feb 13, 2025). Original GitHub issue: https://github.com/kvcache-ai/ktransformers/issues/208 # Environment - ktransformers: 0.2.0+cu128torch24avx2 ( git checkout v0.2.0 and compile) - Device: e5 2686v4 2080ti - torch: '2.4.0+cu121' - system driver: 570 with cuda 12.8 - system cuda: 12.8 # Error Log ## just after first message. I got this error both with driver-cuda 12.4 and 12.8, and model unsloth q2k and q4k. Chat: 你好 Traceback (most recent call last): File "/home/u/prj/ktransformers/./ktransformers/local_chat.py", line 280, in <module> fire.Fire(local_chat) File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/fire/core.py", line 135, in Fire component_trace = _Fire(component, args, parsed_flag_args, context, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/fire/core.py", line 468, in _Fire component, remaining_args = _CallAndUpdateTrace( ^^^^^^^^^^^^^^^^^^^^ File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/fire/core.py", line 684, in _CallAndUpdateTrace component = fn(*varargs, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^ File "/home/u/prj/ktransformers/./ktransformers/local_chat.py", line 274, in local_chat generated = prefill_and_generate( ^^^^^^^^^^^^^^^^^^^^^ File "/home/u/prj/ktransformers/./ktransformers/util/utils.py", line 150, in prefill_and_generate logits = model( ^^^^^^ File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/u/prj/ktransformers/./ktransformers/models/modeling_deepseek_v3.py", line 1688, in forward outputs = self.model( ^^^^^^^^^^^ File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/u/prj/ktransformers/./ktransformers/operators/models.py", line 722, in forward layer_outputs = decoder_layer( ^^^^^^^^^^^^^^ File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/u/prj/ktransformers/./ktransformers/models/modeling_deepseek_v3.py", line 1205, in forward hidden_states, self_attn_weights, present_key_value = self.self_attn( ^^^^^^^^^^^^^^^ File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/u/prj/ktransformers/./ktransformers/operators/attention.py", line 372, in forward return self.forward_chunck( ^^^^^^^^^^^^^^^^^^^^ File "/home/u/prj/ktransformers/./ktransformers/operators/attention.py", line 273, in forward_chunck q = self.q_b_proj(self.q_a_layernorm(self.q_a_proj(hidden_states))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/u/miniconda3/envs/deepseekfp8/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/u/prj/ktransformers/./ktransformers/models/modeling_deepseek_v3.py", line 105, in forward hidden_states = hidden_states.to(torch.float32) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RuntimeError: CUDA error: invalid device function
Author
Owner

@murongweibo commented on GitHub (Feb 13, 2025):

我也遇到这个错误了,是不是对gpu硬件版本有要求?我是在colab申请了一个T4跑的
报错信息:

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.

根据readme文件快速开始跑的结果,挑的DeepSeek-V2-Lite-Chat.Q4_K_M.gguf模型(原来的地址模型是不存在的,估计是大佬已经删了,这里没更新,我换了一个)


# Begin from root of your cloned repo!
# Begin from root of your cloned repo!!
# Begin from root of your cloned repo!!! 

# Download mzwing/DeepSeek-V2-Lite-Chat-GGUF from huggingface
!mkdir DeepSeek-V2-Lite-Chat-GGUF
#%cd DeepSeek-V2-Lite-Chat-GGUF

!wget https://huggingface.co/mradermacher/DeepSeek-V2-Lite-Chat-GGUF/resolve/main/DeepSeek-V2-Lite-Chat.Q4_K_M.gguf -O DeepSeek-V2-Lite-Chat.Q4_K_M.gguf

#%cd .. # Move to repo's root dir

# Start local chat
!python -m ktransformers.local_chat --model_path deepseek-ai/DeepSeek-V2-Lite-Chat --gguf_path ./DeepSeek-V2-Lite-Chat-GGUF

# If you see “OSError: We couldn't connect to 'https://huggingface.co' to load this file”, try:
# GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/deepseek-ai/DeepSeek-V2-Lite
# python  ktransformers.local_chat --model_path ./DeepSeek-V2-Lite --gguf_path ./DeepSeek-V2-Lite-Chat-GGUF
<!-- gh-comment-id:2655695555 --> @murongweibo commented on GitHub (Feb 13, 2025): 我也遇到这个错误了,是不是对gpu硬件版本有要求?我是在colab申请了一个T4跑的 报错信息: ``` 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. ``` 根据readme文件快速开始跑的结果,挑的DeepSeek-V2-Lite-Chat.Q4_K_M.gguf模型(原来的地址模型是不存在的,估计是大佬已经删了,这里没更新,我换了一个) ``` # Begin from root of your cloned repo! # Begin from root of your cloned repo!! # Begin from root of your cloned repo!!! # Download mzwing/DeepSeek-V2-Lite-Chat-GGUF from huggingface !mkdir DeepSeek-V2-Lite-Chat-GGUF #%cd DeepSeek-V2-Lite-Chat-GGUF !wget https://huggingface.co/mradermacher/DeepSeek-V2-Lite-Chat-GGUF/resolve/main/DeepSeek-V2-Lite-Chat.Q4_K_M.gguf -O DeepSeek-V2-Lite-Chat.Q4_K_M.gguf #%cd .. # Move to repo's root dir # Start local chat !python -m ktransformers.local_chat --model_path deepseek-ai/DeepSeek-V2-Lite-Chat --gguf_path ./DeepSeek-V2-Lite-Chat-GGUF # If you see “OSError: We couldn't connect to 'https://huggingface.co' to load this file”, try: # GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/deepseek-ai/DeepSeek-V2-Lite # python ktransformers.local_chat --model_path ./DeepSeek-V2-Lite --gguf_path ./DeepSeek-V2-Lite-Chat-GGUF ```
Author
Owner

@Xxianna commented on GitHub (Feb 13, 2025):

另外我把local_chat.py中设置bf16为默认格式的地方都设为float16了。但是这似乎没有什么帮助。
.to(torch.float32)报错行看起来很奇怪,只是一个转换,单独在torch里执行是没问题的
不知道是否和KLinearMarlin有关?我似乎在另一个issue里看到相关的建议

<!-- gh-comment-id:2655789894 --> @Xxianna commented on GitHub (Feb 13, 2025): 另外我把local_chat.py中设置bf16为默认格式的地方都设为float16了。但是这似乎没有什么帮助。 .to(torch.float32)报错行看起来很奇怪,只是一个转换,单独在torch里执行是没问题的 不知道是否和KLinearMarlin有关?我似乎在另一个issue里看到相关的建议
Author
Owner

@Xxianna commented on GitHub (Feb 13, 2025):

看起来有相关问题
Image
以及看到有人说是flash attention 2 不支持低版本的设备

<!-- gh-comment-id:2655818080 --> @Xxianna commented on GitHub (Feb 13, 2025): 看起来有相关问题 ![Image](https://github.com/user-attachments/assets/3b9ec99b-ae19-4627-aede-5c589fd30935) 以及看到有人说是flash attention 2 不支持低版本的设备
Author
Owner

@20000419 commented on GitHub (Feb 15, 2025):

请问您这个问题现在解决了么

<!-- gh-comment-id:2660898787 --> @20000419 commented on GitHub (Feb 15, 2025): 请问您这个问题现在解决了么
Author
Owner

@Titianzi commented on GitHub (Feb 15, 2025):

V100,也是相同报错,估计就是不支持flash_attn导致的

<!-- gh-comment-id:2660912752 --> @Titianzi commented on GitHub (Feb 15, 2025): V100,也是相同报错,估计就是不支持flash_attn导致的
Author
Owner

@Xxianna commented on GitHub (Feb 16, 2025):

我跑deepseek v2lite也报错,flash_attn有没有问题不知道,ktransformer里那个linear类的.cu感觉得修改才能支持
直接替换lineartorch计算全nan了,这两个类应该不一样吧
虽然准备下单4090了但还是期待一波支持20系

<!-- gh-comment-id:2661215739 --> @Xxianna commented on GitHub (Feb 16, 2025): 我跑deepseek v2lite也报错,flash_attn有没有问题不知道,ktransformer里那个linear类的.cu感觉得修改才能支持 直接替换lineartorch计算全nan了,这两个类应该不一样吧 虽然准备下单4090了但还是期待一波支持20系
Author
Owner

@motu001 commented on GitHub (Mar 26, 2025):

有人解决了吗

<!-- gh-comment-id:2753088045 --> @motu001 commented on GitHub (Mar 26, 2025): 有人解决了吗
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#122
No description provided.