huggingface / huggingface/diffusers

FLUX.1-dev FP8 Example Code Cleanup

オープン
#9,690 コメント 8 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
34.5k
フォーク
7.3k
平均マージ
3日 3時間
マージ済み PR(30日)
91

説明

I was looking at the [FLUX.1-dev FP8 example code](https://huggingface.co/docs/diffusers/main/en/api/pipelines/flux#single-file-loading-for-the-fluxtransformer2dmodel) in the documentation and noticed some unnecessary imports and variable declarations, which make it appear longer and cluttered. Here is the shorter version of the code I'm currently using. Please note that I'm not an expert, just trying to make it easier for anyone else looking to run the code.

```
import torch
from diffusers import FluxTransformer2DModel, FluxPipeline
from transformers import T5EncoderModel
from optimum.quanto import quantize, qfloat8, freeze

bfl_repo = "black-forest-labs/FLUX.1-dev"

transformer = FluxTransformer2DModel.from_single_file("https://huggingface.co/Kijai/flux-fp8/blob/main/flux1-dev-fp8.safetensors", torch_dtype=torch.bfloat16)
quantize(transformer, weights=qfloat8)
freeze(transformer)

text_encoder_2 = T5EncoderModel.from_pretrained(bfl_repo, subfolder="text_encoder_2", torch_dtype=torch.bfloat16)
quantize(text_encoder_2, weights=qfloat8)
freeze(text_encoder_2)

pipe = FluxPipeline.from_pretrained(bfl_repo, transformer=transformer, text_encoder_2=text_encoder_2, torch_dtype=torch.bfloat16)
pipe.enable_model_cpu_offload()

prompt = "A cat holding a sign that says hello world"
image = pipe(
prompt,
generator=torch.Generator("cpu").manual_seed(0)
).images[0]

image.save("flux-dev-fp8.png")
```

Optimizations made:
Removed unnecessary code and reduced the line count from 32 to 26.

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

Diffusers ドキュメントにあるリンク先の FLUX.1-dev FP8 の例から始め、この issue に示されているより短いコードと比較してください。例の動作を維持したまま、不要な import と変数宣言を削除し、その後、ドキュメントのコードが引き続き実行可能であることを確認してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python, pytorch
領域
documentation
issue の種類
ドキュメント
難易度
1/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。