Upload folder using huggingface_hub
Browse files- .gitignore +1 -0
- .vscode/launch.json +46 -0
- .vscode/settings.json +36 -0
- fix_weights.py +25 -0
- ip_adapter.safetensors +3 -0
- test.py +4 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.venv
|
.vscode/launch.json
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"version": "0.2.0",
|
3 |
+
"configurations": [
|
4 |
+
{
|
5 |
+
"name": "Python Debugger: main.py",
|
6 |
+
"type": "debugpy",
|
7 |
+
"request": "launch",
|
8 |
+
"program": "main.py",
|
9 |
+
"console": "integratedTerminal",
|
10 |
+
"justMyCode": false
|
11 |
+
},
|
12 |
+
{
|
13 |
+
"name": "Python: Debug Current File",
|
14 |
+
"type": "debugpy",
|
15 |
+
"request": "launch",
|
16 |
+
"program": "${file}",
|
17 |
+
"console": "integratedTerminal",
|
18 |
+
"justMyCode": false,
|
19 |
+
"args": []
|
20 |
+
},
|
21 |
+
{
|
22 |
+
"name": "Python: pytest",
|
23 |
+
"type": "debugpy",
|
24 |
+
"request": "launch",
|
25 |
+
"program": "./.venv/bin/pytest",
|
26 |
+
"args": [
|
27 |
+
"-s"
|
28 |
+
],
|
29 |
+
"console": "integratedTerminal",
|
30 |
+
"justMyCode": false,
|
31 |
+
},
|
32 |
+
{
|
33 |
+
"name": "Python: torchrun",
|
34 |
+
"type": "debugpy",
|
35 |
+
"request": "launch",
|
36 |
+
"program": "./.venv/bin/torchrun",
|
37 |
+
"args": [
|
38 |
+
"--nproc-per-node=gpu",
|
39 |
+
"--master_port=5535", // change port
|
40 |
+
"main.py"
|
41 |
+
],
|
42 |
+
"console": "integratedTerminal",
|
43 |
+
"justMyCode": false,
|
44 |
+
}
|
45 |
+
],
|
46 |
+
}
|
.vscode/settings.json
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"editor.formatOnSave": true,
|
3 |
+
"python.analysis.autoImportCompletions": true,
|
4 |
+
"python.analysis.useLibraryCodeForTypes": true,
|
5 |
+
"python.languageServer": "Pylance",
|
6 |
+
"ruff.nativeServer": "on",
|
7 |
+
"python.analysis.typeCheckingMode": "standard",
|
8 |
+
"files.trimTrailingWhitespace": true,
|
9 |
+
"files.insertFinalNewline": true,
|
10 |
+
"editor.tabSize": 4,
|
11 |
+
"editor.detectIndentation": false,
|
12 |
+
"editor.renderWhitespace": "all",
|
13 |
+
"editor.rulers": [
|
14 |
+
120
|
15 |
+
],
|
16 |
+
"workbench.colorTheme": "Default Dark Modern",
|
17 |
+
"files.exclude": {
|
18 |
+
"**/__pycache__": true,
|
19 |
+
"**/.venv": true,
|
20 |
+
"**/.mypy_cache": true,
|
21 |
+
"**/.pytest_cache": true,
|
22 |
+
"**/.vscode": false
|
23 |
+
},
|
24 |
+
"[python]": {
|
25 |
+
"editor.codeActionsOnSave": {
|
26 |
+
"source.fixAll": "explicit"
|
27 |
+
}
|
28 |
+
},
|
29 |
+
"search.exclude": {
|
30 |
+
"**/__pycache__": true,
|
31 |
+
"**/.venv": true,
|
32 |
+
"**/.mypy_cache": true,
|
33 |
+
"**/.ruff_cache": true,
|
34 |
+
"**/.pytest_cache": true
|
35 |
+
}
|
36 |
+
}
|
fix_weights.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from safetensors.torch import save_file
|
3 |
+
|
4 |
+
# Load the original .bin file
|
5 |
+
orig = torch.load("pytorch_model.bin", map_location="cpu")
|
6 |
+
converted = {}
|
7 |
+
|
8 |
+
# Convert ip_adapter weights
|
9 |
+
for key, value in orig["ip_adapter"].items():
|
10 |
+
# e.g. '0.to_k_ip.weight' → 'ip_adapter.0.to_k_ip.weight'
|
11 |
+
parts = key.split(".", 1)
|
12 |
+
if len(parts) == 2:
|
13 |
+
new_key = f"ip_adapter.{parts[0]}.{parts[1]}"
|
14 |
+
else:
|
15 |
+
new_key = f"ip_adapter.{key}"
|
16 |
+
converted[new_key] = value
|
17 |
+
|
18 |
+
# Convert image_proj weights
|
19 |
+
for key, value in orig["image_proj"].items():
|
20 |
+
# Do not rename! Just prepend with 'image_proj.'
|
21 |
+
new_key = f"image_proj.{key}"
|
22 |
+
converted[new_key] = value
|
23 |
+
|
24 |
+
# Save to safetensors
|
25 |
+
save_file(converted, "ip_adapter.safetensors")
|
ip_adapter.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:80dcdcef255b42119f97341d8dd643c59e013ab2115e8e244b0fbeaaac0ce07d
|
3 |
+
size 1595885576
|
test.py
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from diffusers import StableDiffusion3Pipeline
|
2 |
+
|
3 |
+
pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3.5-large", torch_dtype="auto")
|
4 |
+
pipe.load_ip_adapter("/root/SD3.5-Large-IP-Adapter/ip_adapter.safetensors", image_encoder_folder="google/siglip-so400m-patch14-384")
|