diffusers icon indicating copy to clipboard operation
diffusers copied to clipboard

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

Open starinskycc opened this issue 1 year ago • 5 comments

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 avatar Apr 28 '24 10:04 starinskycc

Could you also set --variant=fp16?

tolgacangoz avatar Apr 28 '24 10:04 tolgacangoz

not set

starinskycc avatar Apr 28 '24 10:04 starinskycc

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

starinskycc avatar Apr 28 '24 10:04 starinskycc

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.

bghira avatar Apr 30 '24 00:04 bghira

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

starinskycc avatar May 03 '24 01:05 starinskycc

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.

github-actions[bot] avatar Sep 14 '24 15:09 github-actions[bot]