huggingface / huggingface/candle

Candle Inference ~8.5x Slower Than PyTorch on CPU

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

Description

## Issue

Inference with the `sentence-transformers/all-MiniLM-L6-v2` model using `candle-transformers` (v0.8.4) is significantly slower (approximately 8.5 times) compared to the standard PyTorch implementation using transformers and PyTorch. The average time per batch (size 4) is around 122.30 ms in Candle versus ~14.34 ms in PyTorch.

## Environment

* **Candle Version**: 0.8.4 (using `candle-core`, `candle-nn`, `candle-transformers`)
* **Candle Features**: `cuda`, `cudnn`, `mkl`
* **CUDA Version**: 12.8 (V12.8.93)
* **Model**: `sentence-transformers/all-MiniLM-L6-v2`
* **Batch Size**: 4
* **Hardware**: i9-13900HX
* **Operating System**: Windows 11

## Profiling Data (Batch Size = 4)

Time taken for the forward pass.

| Language | Operation | Mean (ms) | Std (ms) | Min (ms) | Max (ms) |
| :------- | :------------ | :-------- | :------- | :------- | :------- |
| Python PyTorch | Inference (ms) | 14.34 | 3.15 | 8.00 | 120.78 |
| Rust Candle | Inference (ms) | 122.30 | 43.38 | 18.00 | 319.00 |

## Expected Result

Inference time should be closer to the PyTorch performance, ideally around 14-20 ms on CPU. I am observing Candle GPU performance better than PyTorch vanilla.

## Actual Result

The average inference time with Candle is ~122.30 ms per batch, with significant variance (standard deviation: 43.38 ms). This is much slower than expected and slower than previous reports comparing Candle and Python implementations for this model.

Contributor guide

No contributing guide indexed for this repository

Research direction

No source files or tests are named. Start by reproducing the reported sentence-transformers/all-MiniLM-L6-v2 batch-size-4 benchmark with Candle 0.8.4 on the stated CPU setup, then compare its forward-pass timing with PyTorch and inspect the relevant Candle inference path. Done means identifying and addressing the cause of the CPU slowdown, with measurements showing the resulting performance.

Written by the indexing model from the issue text.

Assessment

Tech stack
pytorch, rust
Domain
machine-learning, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.