Upload converttoP.py
Browse files- converttoP.py +18 -0
converttoP.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import torch
|
3 |
+
import safetensors
|
4 |
+
from safetensors.torch import save_file
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
+
model = safetensors.safe_open('sd3_medium_incl_clips_t5xxlfp16.safetensors', 'pt')
|
7 |
+
keys = model.keys()
|
8 |
+
dic = {key:model.get_tensor(key) for key in keys}
|
9 |
+
parts = ['diffusion_model']
|
10 |
+
count = 0
|
11 |
+
for k in keys:
|
12 |
+
if all(i in k for i in parts):
|
13 |
+
v = dic[k]
|
14 |
+
print(f'{k}: {v.std()}')
|
15 |
+
dic[k] += torch.normal(torch.zeros_like(v)*v.mean(), torch.ones_like(v)*v.std()*.02)
|
16 |
+
count += 1
|
17 |
+
print(count)
|
18 |
+
save_file(dic, 'sd3_medium_incl_clips_t5xxlfp16.safetensors_perturbed3.safetensors', model.metadata())
|