kohya-ss / kohya-ss/sd-scripts
SVD merge - AttributeError: 'float' object has no attribute 'to'
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 1.2k
- Avg merge
- 11m
- Merged PRs (30d)
- 2
Description
I get the following error when merging two models:
```
16:34:54-130582 INFO ./venv/Scripts/python.exe "networks\svd_merge_lora.py" --save_precision float --precision float
--save_to "C:/Users/username/Git/stable-diffusion-webui/models/Lora/Styles/90sv1990.safetensors"
--models "C:/Users/username/Git/stable-diffusion-webui/models/Lora/Styles/1990s.safetensors"
"C:/Users/username/Git/stable-diffusion-webui/models/Lora/Styles/90sv1.6R.safetensors" --ratios
0.5 0.5 --device cuda --new_rank "128" --new_conv_rank "128"
A matching Triton is not available, some optimizations will not be enabled.
Error caught was: No module named 'triton'
new rank: 128, new conv rank: 128
loading: C:/Users/username/Git/stable-diffusion-webui/models/Lora/Styles/1990s.safetensors
C:\Users\username\Git\kohya_ss\venv\lib\site-packages\safetensors\torch.py:98: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly. To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()
with safe_open(filename, framework="pt", device=device) as f:
merging...
0%| | 0/528 [00:00 │
│ │
│ 189 parser = setup_parser() │
│ 190 │
│ 191 args = parser.parse_args() │
│ ❱ 192 merge(args) │
│ 193 │
│ │
│ C:\Users\username\Git\kohya_ss\networks\svd_merge_lora.py:161 in merge │
│ │
│ 158 │ save_dtype = merge_dtype │
│ 159 │
│ 160 new_conv_rank = args.new_conv_rank if args.new_conv_rank is not None else args.new_ran │
│ ❱ 161 state_dict = merge_lora_models(args.models, args.ratios, args.new_rank, new_conv_rank, │
│ 162 │
│ 163 print(f"saving model to: {args.save_to}") │
│ 164 save_to_file(args.save_to, state_dict, save_dtype) │
│ │
│ C:\Users\username\Git\kohya_ss\networks\svd_merge_lora.py:82 in merge_lora_models │
│ │
│ 79 │ scale = (alpha / network_dim) │
│ 80 │ │
│ 81 │ if device: # and isinstance(scale, torch.Tensor): │
│ ❱ 82 │ │ scale = scale.to(device) │
│ 83 │ │
│ 84 │ if not conv2d: # linear │
│ 85 │ │ weight = weight + ratio * (up_weight @ down_weight) * scale │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
AttributeError: 'float' object has no attribute 'to'
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in networks/svd_merge_lora.py at merge_lora_models, especially line 82 where scale.to(device) raises the error. Reproduce the provided SVD merge command and inspect how scale is calculated immediately before that call. Done means the merge completes past this point and writes the requested safetensors output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100