Views
No views yet
https://huggingface.co/LifuWang/DistillT5model.safetensorsE5M2model-lora-r64-all.safetensors if availablemodel-fp8-e5m2.safetensors1from safetensors.torch import load_file
2import torch
3
4# Load FP8 model
5fp8_state = load_file("model-fp8-e5m2.safetensors")
6
7# Load precision recovery file if available
8recovery_state = {}
9if "model-lora-r64-all.safetensors":
10 recovery_state = load_file("model-lora-r64-all.safetensors")
11
12# Reconstruct high-precision weights
13reconstructed = {}
14for key in fp8_state:
15 # Dequantize FP8 to target precision
16 fp_weight = fp8_state[key].to(torch.float32)
17
18 if recovery_state:
19 # For LoRA approach
20 if f"lora_A.{key}" in recovery_state and f"lora_B.{key}" in recovery_state:
21 A = recovery_state[f"lora_A.{key}"].to(torch.float32)
22 B = recovery_state[f"lora_B.{key}"].to(torch.float32)
23 error_correction = B @ A
24 reconstructed[key] = fp_weight + error_correction
25 # For correction factor approach
26 elif f"correction.{key}" in recovery_state:
27 correction = recovery_state[f"correction.{key}"].to(torch.float32)
28 reconstructed[key] = fp_weight + correction
29 else:
30 reconstructed[key] = fp_weight
31 else:
32 reconstructed[key] = fp_weight
33
34print("Model reconstructed with FP8 error recovery")Note: This precision recovery targets FP8 quantization errors. Average quantization error: 0.052733