Closed frankjiang closed 10 months ago
i believe for this to work you have to write the script in such a way that the functions are not included in the main operating context, as it is telling you at the bottom that you cannot pickle a function.
it is trying to pickle things and essentially serialise them for consumption in child processes. it is quite annoying.
you will have to refactor that script to instead rely on external modules. but that's something that isn't likely to be supported by Huggingface, it goes against the philosophy document.
can you identify why it works in SD 1.5 but not SDXL?
i believe for this to work you have to write the script in such a way that the functions are not included in the main operating context, as it is telling you at the bottom that you cannot pickle a function.
it is trying to pickle things and essentially serialise them for consumption in child processes. it is quite annoying.
you will have to refactor that script to instead rely on external modules. but that's something that isn't likely to be supported by Huggingface, it goes against the philosophy document.
can you identify why it works in SD 1.5 but not SDXL?
Following the log, the error happens in preprocress_train
Compared to SD 1.5 version, there are differences
# SD 1.5
captions = list(examples[edit_prompt_column])
examples["input_ids"] = tokenize_captions(captions)
# SDXL
captions = list(examples[edit_prompt_column])
prompt_embeds_all, add_text_embeds_all = compute_embeddings_for_prompts(captions, text_encoders, tokenizers)
examples["prompt_embeds"] = prompt_embeds_all
examples["add_text_embeds"] = add_text_embeds_all
in which
# Adapted from examples.dreambooth.train_dreambooth_lora_sdxl
# Here, we compute not just the text embeddings but also the additional embeddings
# needed for the SD XL UNet to operate.
def compute_embeddings_for_prompts(prompts, text_encoders, tokenizers):
with torch.no_grad():
prompt_embeds_all, pooled_prompt_embeds_all = encode_prompts(text_encoders, tokenizers, prompts)
add_text_embeds_all = pooled_prompt_embeds_all
prompt_embeds_all = prompt_embeds_all.to(accelerator.device)
add_text_embeds_all = add_text_embeds_all.to(accelerator.device)
return prompt_embeds_all, add_text_embeds_all
I'm not sure, if the inner function is to blame.
Could be because of the interplay between pre-computing (which utilizes GPUs) and the spawning of multiple threads.
So, it's recommended to not use multiple workers here.
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.
Please note that issues that do not follow the contributing guidelines are likely to be ignored.
Describe the bug
Short Description
Run the training with
train_instruct_pix2pix_sdxl.py
It fails on --dataloader_num_workersRuntimeError: Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the 'spawn' start method
What have I tried
I found:
--dataloader_num_workers
works fine in scripttrain_instruct_pix2pix.py
I've tried to add the following code on the beginning, still failed.
The main log part after specify spawn:
Reproduction
Logs
System Info
diffusers-cli env
diffusers
version: 0.20.0.dev0Who can help?
@williamberman @sayakpaul