huggingface / diffusers

🤗 Diffusers: State-of-the-art diffusion models for image and audio generation in PyTorch and FLAX.
https://huggingface.co/docs/diffusers
Apache License 2.0
26.45k stars 5.45k forks source link

set mixed_precision="fp16",but the model is not fp16 #7801

Open starinskycc opened 7 months ago

starinskycc commented 7 months ago

Describe the bug

I trained the control net of SDXL using the mixed prediction="fp16" parameter, but the trained model did not have the suffix. fp16. safetensors. But it's a 5G file. I see that the Controlnet on HuggFace will have a 5G file and a 2.5G file with fp16.

Reproduction

accelerate launch train_controlnet_sdxl.py --pretrained_model_name_or_path=$MODEL_DIR --output_dir=$OUTPUT_DIR --pretrained_vae_model_name_or_path=$VAE --dataset_name=/root/autodl-tmp/datasets/ --mixed_precision="fp16" --resolution=1024 --learning_rate=1e-5 --max_train_steps=20000 --validation_image "/root/test.jpg" --validation_prompt "bedroom" --validation_steps=500 --train_batch_size=2 --gradient_accumulation_steps=4 --report_to="wandb" --seed=42 --checkpointing_steps=2000 --cache_dir=/root/autodl-tmp/cache/

Logs

No response

System Info

diffuser 0.28 , linux, python 3.10.11

Who can help?

No response

starinskycc commented 7 months ago

not set

starinskycc commented 7 months ago

As long as I set --variant=fp16, can I output the ".fp16.safetensors" model ?

bghira commented 7 months ago

it's kind of annoying currently to actually export fp16 weights, but with just a few lines of python, you will have it done easily:

from diffusers.pipelines import DiffusionPipeline
import torch

model_id = 'username/model-name'
output_dir = '/path/to/new/pipeline'

pipeline = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipeline.save_pretrained(output_dir, use_safetensors=True)

note that the name won't include '.fp16.' but you can manually rename it to include.

starinskycc commented 7 months ago

it's kind of annoying currently to actually export fp16 weights, but with just a few lines of python, you will have it done easily:

from diffusers.pipelines import DiffusionPipeline
import torch

model_id = 'username/model-name'
output_dir = '/path/to/new/pipeline'

pipeline = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipeline.save_pretrained(output_dir, use_safetensors=True)

note that the name won't include '.fp16.' but you can manually rename it to include.

thank u

github-actions[bot] commented 2 months ago

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.