kohya-ss / kohya-ss/sd-scripts
"maximum recursion depth" error when copy.deepcopy(unet) in gen_img.py
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 1.2k
- Avg merge
- 11m
- Merged PRs (30d)
- 2
Description
### Reproduce
Using v1-5-pruned.safetensors in https://huggingface.co/runwayml/stable-diffusion-v1-5/tree/main
Add
```
import copy
copy.deepcopy(unet)
```
after this line
https://github.com/kohya-ss/sd-scripts/blob/f9317052edb4ab3b3c531ac3b28825ee78b4a966/gen_img.py#L1556
### Error stack trace
```
File "/home/tsogzark/miniconda3/envs/kohyass/lib/python3.10/copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/home/tsogzark/miniconda3/envs/kohyass/lib/python3.10/copy.py", line 272, in _reconstruct
if hasattr(y, '__setstate__'):
File "/home/fz/mydisk/Zqh/Cv/kohya_ss/sd-scripts/library/original_unet.py", line 1709, in __getattr__
return getattr(self.delegate, name)
File "/home/fz/mydisk/Zqh/Cv/kohya_ss/sd-scripts/library/original_unet.py", line 1709, in __getattr__
return getattr(self.delegate, name)
File "/home/fz/mydisk/Zqh/Cv/kohya_ss/sd-scripts/library/original_unet.py", line 1709, in __getattr__
return getattr(self.delegate, name)
[Previous line repeated 991 more times]
RecursionError: maximum recursion depth exceeded
```
### Extra infomation
- It works when deepcopy unet in sdxl_gen_img.py
- It works well when remove these two lines.
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the failure in gen_img.py around line 1556 using v1-5-pruned.safetensors. Then inspect library/original_unet.py around line 1709 and compare the deepcopy path with sdxl_gen_img.py, where it reportedly works. Done means copy.deepcopy(unet) completes without the recursion error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100