Skip to content

demo_page_hf: use float16 on CUDA and float32 on CPU to fix 'slow_conv2d_cpu' Half error - #122

Merged
fh2019ustc merged 1 commit into
bytedance:masterfrom
ktyptorio:fix/cpu-fp32-demo_page_hf
Aug 13, 2025
Merged

demo_page_hf: use float16 on CUDA and float32 on CPU to fix 'slow_conv2d_cpu' Half error#122
fh2019ustc merged 1 commit into
bytedance:masterfrom
ktyptorio:fix/cpu-fp32-demo_page_hf

Conversation

@ktyptorio

Copy link
Copy Markdown
Contributor

Problem

Running demo_page_hf.py on CPU fails with: “slow_conv2d_cpu not implemented for 'Half'”.

Root cause

Both the model and pixel_values were always forced to float16, even when running on CPU.

Fix

  • Model precision: call half() only when CUDA is available; use float() on CPU.
  • Input precision: use pixel_values.half() only on CUDA; use pixel_values.float() on CPU.

Impact

  • CPU inference no longer errors.
  • CUDA path still benefits from FP16 performance.
  • No API changes.

Scope

  • File: demo_page_hf.py only.

@fh2019ustc
fh2019ustc merged commit 50b3af2 into bytedance:master Aug 13, 2025
Alberto02003 pushed a commit to Alberto02003/Dolphin that referenced this pull request Sep 27, 2025
Fixes 'slow_conv2d_cpu' Half error when running demo_page_hf.py on CPU.

- Use float16 precision only on CUDA devices for performance
- Use float32 precision on CPU for compatibility
- Maintains backward compatibility with existing CUDA workflows

Resolves bytedance#122
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants