huggingface / huggingface/candle

No Rayon mode

Open
#3,134 8 comments 4 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
21k
Forks
1.8k
Avg merge
16h 42m
Merged PRs (30d)
25

Description

Hi candle devs!

I'm using candle to inference a small model (Qwen-0.6B-4b) using CPU. Profiling the inference show that there's significant overhead in rayon processing, primarily because too fine-grained multi-thread partitions, i.e., the overhead of thread communication is more expensive than the benefits it brings. Even if I set `RAYON_NUM_THREADS=1` the overhead of thread management, cache affinity penalty, etc is still high.

I made a small prototype that removes most of the rayon use here: https://github.com/XiangpengHao/candle/tree/ed0fcc9428d8a0b11838d8b488dc40a7ac89fcc1

I run a small benchmark with qwen-0.6B-4b, using the current main I got 53.62 token/s (use all threads); without rayon (so it's single threaded), I got 69.54 token/s.

I suggest we (1) offer a way to opt-out rayon, and (2) optimize multi-thread cpu inference so that it can fully use the CPU resources.

Related: #2499 #1103 #2877

If you are open to the changes, I'm happy to work on it!

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by comparing Candle's current main with the linked prototype commit, then reproduce the Qwen-0.6B-4b CPU benchmark described in the issue. The work is done when users can opt out of Rayon and CPU inference achieves the intended improvement without Rayon overhead; review related issues #2499, #1103, and #2877 for context.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
machine-learning, performance
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.