Skip to content

Commit 6874a5b

Browse files
yossiovadiaclaude
andcommitted
fix(training): force FP32 precision for PII LoRA training to fix uniform 0.9 confidence
Issue vllm-project#647 reported uniform 0.9 confidence scores in PII detection. Root cause: Training with FP16 (torch.float16) compresses confidence score distributions due to limited mantissa precision (~10-11 significant bits). Token classification requires precise per-token probability distributions. Fix: Force torch.float32 for all PII token classification training, ensuring proper confidence score variance and accurate entity detection probabilities. This fix complements PR vllm-project#648 which enables LoRA PII model auto-detection. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Yossi Ovadia <[email protected]>
1 parent 68525f2 commit 6874a5b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/training/training_lora/pii_model_fine_tuning_lora/pii_bert_finetuning_lora.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,12 @@ def create_lora_token_model(model_name: str, num_labels: int, lora_config: dict)
149149
tokenizer.pad_token = tokenizer.eos_token
150150

151151
# Load base model for token classification
152+
# Force FP32 for proper confidence score distribution (FP16 causes uniform ~0.9 scores)
153+
# Issue #647: FP16 limited precision (10-11 bits) compresses confidence distributions
152154
base_model = AutoModelForTokenClassification.from_pretrained(
153155
model_name,
154156
num_labels=num_labels,
155-
dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
157+
torch_dtype=torch.float32, # Always use FP32 for stable token classification
156158
)
157159

158160
# Create LoRA configuration for token classification

0 commit comments

Comments
 (0)