Instructions to use ProCreations/Image-2.1-Calibrated-FP8 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use ProCreations/Image-2.1-Calibrated-FP8 with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("ProCreations/Image-2.1-Calibrated-FP8", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
- DiffusionBee
Accelerate full 40-step FP8 generation with native precision, measured quality and real-time demo
1081be0 verified Download optimization/source/validate.py from ProCreations/Image-2.1-Calibrated-FP8: direct link, hf CLI and curl.
- Browser
- Download file 2.49 kB
-
https://huggingface.co/ProCreations/Image-2.1-Calibrated-FP8/resolve/main/optimization/source/validate.py
- Command line
-
hf download hf://ProCreations/Image-2.1-Calibrated-FP8/optimization/source/validate.py
-
curl -L -o validate.py https://huggingface.co/ProCreations/Image-2.1-Calibrated-FP8/resolve/main/optimization/source/validate.py
2.49 kB
| import sys,time,json,argparse,collections | |
| from pathlib import Path | |
| import torch | |
| from PIL import Image | |
| from safetensors.torch import save_file | |
| ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT)) | |
| from fp8_runtime import load_pipeline,CalibratedFP8Linear | |
| from prompts import EVALUATION | |
| ap=argparse.ArgumentParser();ap.add_argument('--mode',choices=['exact','sage'],default='exact');ap.add_argument('--dynamic',action='store_true');ap.add_argument('--cache',type=float,default=0);ap.add_argument('--indices',default='all');args=ap.parse_args() | |
| out=Path(__file__).parent/(f'validation-{args.mode}-{args.cache}'+('-dynamic' if args.dynamic else ''));out.mkdir(exist_ok=True) | |
| def main(): | |
| pipe=load_pipeline('/home/user/models/qwen-image-2.1-b3179ad',ROOT/'release/transformer') | |
| if args.dynamic: | |
| from acceleration import accelerate_pipeline | |
| accelerate_pipeline(pipe) | |
| else:raise ValueError('This release validates --mode exact --dynamic only') | |
| assert args.mode=='exact' and not args.cache | |
| cache=None | |
| rows=[] | |
| indices=list(range(16)) if args.indices=='all' else [int(x) for x in args.indices.split(',')] | |
| for i in indices: | |
| prompt=EVALUATION[i];w=h=2048 if i%4==0 else 1024 | |
| if i==12:w,h=1536,864 | |
| if i==13:w,h=864,1536 | |
| latest={} | |
| def cb(p,step,t,kw): | |
| if step==39:latest['latents']=kw['latents'].detach() | |
| return kw | |
| torch.cuda.synchronize();t=time.perf_counter() | |
| im=pipe(prompt=prompt,width=w,height=h,num_inference_steps=40,generator=torch.Generator('cuda').manual_seed(20000+i),callback_on_step_end=cb).images[0] | |
| torch.cuda.synchronize();sec=time.perf_counter()-t;im.save(out/f'{i:02d}.png') | |
| save_file({'latents':latest['latents'].cpu().contiguous()},str(out/f'{i:02d}-latents.safetensors')) | |
| row={'index':i,'seconds':sec,'reused':cache.skips if cache else 0};rows.append(row);(out/'runs.json').write_text(json.dumps(rows,indent=2));print(json.dumps(row),flush=True) | |
| if args.indices=='all': | |
| for j,prompt in enumerate(['Replace the background with a blooming spring garden and preserve the animal.','Turn this room into a warm evening scene with lamps switched on, preserving its furniture.']): | |
| im=Image.open(ROOT/'evaluation/bf16'/f'{[0,3][j]:02d}.png').resize((1024,1024)) | |
| result=pipe(prompt=prompt,image=im,width=1024,height=1024,num_inference_steps=40,generator=torch.Generator('cuda').manual_seed(21000+j)).images[0] | |
| result.save(out/f'edit-{j}.png');print('EDIT',j,flush=True) | |
| print('COMPLETE',flush=True) | |
| main() | |