Views
No views yet
https://huggingface.co/lllyasviel/control_v11p_sd15_segdiffusion_pytorch_model.fp16.safetensorsE5M2diffusion_pytorch_model.fp16-fp8-e5m2.safetensorsdiffusion_pytorch_model.fp16-recovery.safetensors1[
2 {
3 "key_pattern": "vae",
4 "dim": 4,
5 "method": "diff"
6 },
7 {
8 "key_pattern": "encoder",
9 "dim": 4,
10 "method": "diff"
11 },
12 {
13 "key_pattern": "decoder",
14 "dim": 4,
15 "method": "diff"
16 },
17 {
18 "key_pattern": "text",
19 "dim": 2,
20 "min_size": 10000,
21 "method": "lora",
22 "rank": 64
23 },
24 {
25 "key_pattern": "emb",
26 "dim": 2,
27 "min_size": 10000,
28 "method": "lora",
29 "rank": 64
30 },
31 {
32 "key_pattern": "attn",
33 "dim": 2,
34 "min_size": 10000,
35 "method": "lora",
36 "rank": 128
37 },
38 {
39 "key_pattern": "conv",
40 "dim": 4,
41 "method": "diff"
42 },
43 {
44 "key_pattern": "resnet",
45 "dim": 4,
46 "method": "diff"
47 },
48 {
49 "key_pattern": "all",
50 "method": "none"
51 }
52]1from safetensors.torch import load_file
2import torch
3
4# Load FP8 model
5fp8_state = load_file("diffusion_pytorch_model.fp16-fp8-e5m2.safetensors")
6
7# Load recovery weights if available
8recovery_state = load_file("diffusion_pytorch_model.fp16-recovery.safetensors") if "diffusion_pytorch_model.fp16-recovery.safetensors" and os.path.exists("diffusion_pytorch_model.fp16-recovery.safetensors") else {}
9
10# Reconstruct high-precision weights
11reconstructed = {}
12for key in fp8_state:
13 fp8_weight = fp8_state[key].to(torch.float32) # Convert to float32 for computation
14
15 # Apply LoRA recovery if available
16 lora_a_key = f"lora_A.{key}"
17 lora_b_key = f"lora_B.{key}"
18 if lora_a_key in recovery_state and lora_b_key in recovery_state:
19 A = recovery_state[lora_a_key].to(torch.float32)
20 B = recovery_state[lora_b_key].to(torch.float32)
21 # Reconstruct the low-rank approximation
22 lora_weight = B @ A
23 fp8_weight = fp8_weight + lora_weight
24
25 # Apply difference recovery if available
26 diff_key = f"diff.{key}"
27 if diff_key in recovery_state:
28 diff = recovery_state[diff_key].to(torch.float32)
29 fp8_weight = fp8_weight + diff
30
31 reconstructed[key] = fp8_weight
32
33# Use reconstructed weights in your model
34model.load_state_dict(reconstructed)Note: For best results, use the same recovery configuration during inference as was used during extraction. Requires PyTorch ≥ 2.1 for FP8 support.