huggingface / huggingface/candle
Mistral-7b model in rust candle example is slower than python Mistral-7b
- Dominant language
- Rust
- Stars
- 21k
- Forks
- 1.8k
- Avg merge
- 16h 42m
- Merged PRs (30d)
- 25
Description
I expected the Rust version to be faster, but it is actually slower than the Python version,
obviously, I tested a few times more, so I did warming up.
please give me advice for some accurate benchmark so I can share it after testing.
cpu: AMD Ryzen 9 5950x 16-Core Processor
Ram: 128GB
GPU: RTX 3090 24GB
rust docker image -> rust official docker image, cuda 12.2 from host to container
python docker image -> datascience-notebook, cuda 12.2 from host to container
rust model id -> lmz/candle-mistral
python model id -> mistralai/Mistral-7B-Instruct-v0.1
The candle library was tested by copying the GitHub source.
python main library versions
torch 2.0.1 + cu118
transformers 4.34.0.dev0
accelerate 0.23.0
python
rust example link : https://github.com/huggingface/candle/tree/main/candle-examples/examples/mistral
rust command
cargo run --example mistral --release --features cuda -- --prompt 'Write fibonacci code in golang' --sample-len 300
result
**35.94 token/s**
python code
```
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
import time
device = "cuda" # the device to load the model onto
model_path = "mistralai/Mistral-7B-Instruct-v0.1"
# torch.float32 OOM
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=torch.float16)
tokenizer = AutoTokenizer.from_pretrained(model_path)
model.to(device)
start = time.time()
message = "[INST] write fibonacci code in golang [/INST]"
input_ids = tokenizer(message,return_tensors="pt")["input_ids"].to(device)
generated_ids = model.generate(input_ids, max_length=300, do_sample=True)
decoded = tokenizer.batch_decode(generated_ids)
end = time.time() - start
token_per_second = generated_ids[0][17:].shape[0] / end
print("result",decoded[0])
print("token length", generated_ids[0][17:].shape[0])
print("token per second", token_per_second)
```
result
**42.58 token/s**
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.