huggingface / huggingface/candle

Hang in quantized_phi::ModelWeights::forward() with Phi-2 GGUF on CPU (Candle main branch)

Open
#2,976 0 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

Description:
The program hangs indefinitely when calling the forward() method on a quantized_phi::ModelWeights instance loaded from a Phi-2 GGUF file. This occurs during the first iteration of token generation, specifically after printing a log message "Calling model.forward()..." and before any indication that the forward() call has completed. The test is performed using a minimal, standalone Candle program on CPU.

Environment:

Candle Version: main branch (commit 0224a749 as per user's cargo build log for the test project)
candle-core v0.9.1 (https://github.com/huggingface/candle.git?branch=main#0224a749)
candle-nn v0.9.1 (https://github.com/huggingface/candle.git?branch=main#0224a749)
candle-transformers v0.9.1 (https://github.com/huggingface/candle.git?branch=main#0224a749)
OS: Windows 11 Pro
CPU: Intel(R) Core(TM) i5-9400 CPU @ 2.90GHz 2.90 GHz
Rust Version: rustc 1.87.0
Target: CPU (explicitly set Device::Cpu)
SIMD Features Reported by Test: avx: false, neon: false, simd128: false, f16c: false
Model and Tokenizer Information:

Model Type: candle_transformers::models::quantized_phi::ModelWeights
GGUF File: phi-2.Q4_K_M.gguf
Source: Downloaded from a Hugging Face Hub repository. (User: Please specify which exact repository if possible when submitting, e.g., "TheBloke/phi-2-GGUF" or "microsoft/phi-2".)
Tokenizer File: tokenizer.json (corresponding to Phi-2)
Source: Downloaded from a Hugging Face Hub repository. (User: Please specify which exact repository if possible, e.g., from "microsoft/phi-2" or the same repo as the GGUF.)
Minimal Reproducible Example (MRE):

Project Name: candle_phi2_test
Cargo.toml:

Steps to Reproduce:

Create a new Rust project: cargo new candle_phi2_test_report
Replace candle_phi2_test_report/Cargo.toml with the Cargo.toml content above.
Replace candle_phi2_test_report/src/main.rs with the src/main.rs content above.
Important for Candle Team: Obtain phi-2.Q4_K_M.gguf and a corresponding tokenizer.json from a Hugging Face Hub repository (e.g., "TheBloke/phi-2-GGUF" for the model, "microsoft/phi-2" for the tokenizer). Place them in a location accessible by the paths specified in model_path_str and tokenizer_path_str in src/main.rs (or update the paths in the code).
Run cargo build.
Run cargo run.
Observed Behavior:
The program successfully loads the model and tokenizer. It encodes the prompt and enters the generation loop. In the first iteration of the loop, the following console output is observed before the program hangs:

Starting standalone Candle Phi-2 GGUF test...
avx: false, neon: false, simd128: false, f16c: false
Device: CPU
Loading tokenizer from: C:/Users/Admin/Projects/mobiunt/backend/models/phi-2/tokenizer.json
Tokenizer loaded successfully.
Loading model from: C:/Users/Admin/Projects/mobiunt/backend/models/phi-2/phi-2.Q4_K_M.gguf
GGUF content read. Attempting to load model weights...
Model weights loaded successfully.
Encoding prompt: 'Rephrase this: What is the capital of France?'
Prompt encoded into 12 tokens: [6207, 11840, 589, 428, 25, 1867, 318, 262, 3139, 286, 4881, 30]
EOS token ID used for stopping: Some(50256) (Note: u32::MAX means no specific EOS token was found with common names)

Starting generation (max_new_tokens: 5)...
Iteration 1/5: start_pos=0, context_size=12, input_tokens_slice_len=12
Iteration 1: Input tensor shape: [1, 12]
Iteration 1: Calling model.forward()...
After printing "Calling model.forward()...", the program becomes unresponsive and hangs indefinitely. No further log messages are printed, and the program does not exit or panic.

Expected Behaviour:
The model.forward() call should complete. The program should then proceed to sample a token, print it, and either complete max_new_tokens (5) itera

[main.txt](https://github.com/user-attachments/files/20534542/main.txt)
[cargo.txt](https://github.com/user-attachments/files/20534543/cargo.txt)

tions or stop if an EOS token is generated. It should then print the "Generation Complete" summary and exit cleanly.

Additional Notes:

The model variable in the MRE is declared as mut model. This was based on previous debugging in a more complex Axum application where compiler errors (E0596) suggested ModelWeights::forward required &mut self. The same hang occurs whether model is mut or not in this standalone test, as long as the forward call is made.
The issue is observed on CPU. GPU capabilities were not explicitly tested but are not expected to be a factor given the CPU target and SIMD features reported.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.