Update README for Remote Text Encoding architecture
Browse files12345678910111213141516171819202125 unmodified lines474849505152539 unmodified lines63646566676869707172737475767778798068 unmodified lines149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251# FLUX.2-dev Handler for HuggingFace Dedicated EndpointsHigh-performance image generation using FLUX.2-dev with FP8 quantization for HuggingFace Dedicated Endpoints.## Features- **FP8 Quantization**: Via torchao for memory efficiency- **Multi-Reference Images**: Up to 10 reference images for character/style consistency- **torch.compile**: Optimized inference with reduce-overhead mode- **1920x1080 Output**: Full HD resolution by default## GPU Requirements| GPU | VRAM | Mode | Recommended ||-----|------|------|-------------|| H200 | 141GB | Full GPU + FP8 + compile | Best || H100 | 80GB | Full GPU + FP8 + compile | Good || A100 | 80GB | Full GPU + FP8 | Minimum |## Deployment Steps25 unmodified lines# Commit and pushgit add .git commit -m "Add FLUX.2-dev handler"git push```9 unmodified lines- **Scaling**: Min 0, Max 1 (scale-to-zero enabled)- **Scale-to-Zero Timeout**: 15 minutes4. Environment Variables:- `HF_TOKEN`: Your HuggingFace token (for gated model access)- `USE_FP8`: `true`- `USE_COMPILE`: `true`- `NUM_INFERENCE_STEPS`: `50`5. Click "Create Endpoint"### 4. Wait for DeploymentFirst deployment takes 10-15 minutes to:- Download FLUX.2-dev model (~60GB)- Apply FP8 quantization- Run torch.compile warmup### 5. Test the Endpoint68 unmodified lines| Variable | Default | Description ||----------|---------|-------------|| `HF_TOKEN` | - | HuggingFace token (required) || `USE_FP8` | `true` | Enable FP8 quantization || `USE_COMPILE` | `true` | Enable torch.compile || `NUM_INFERENCE_STEPS` | `50` | Default inference steps |## Endpoint Management### Scale to Zero Manually```pythonfrom huggingface_hub import HfApiapi = HfApi()api.scale_to_zero_inference_endpoint('flux2-dev-handler',namespace='YOUR_USERNAME')```### Update Scale-to-Zero Timeout```pythonfrom huggingface_hub import HfApiapi = HfApi()api.update_inference_endpoint('flux2-dev-handler',namespace='YOUR_USERNAME',scale_to_zero_timeout=15 # minutes)```### Resume Endpoint```pythonfrom huggingface_hub import HfApiapi = HfApi()api.resume_inference_endpoint('flux2-dev-handler',namespace='YOUR_USERNAME')```## Frontend Integration```typescript// services/huggingfaceService.tsconst HF_TOKEN = import.meta.env.VITE_HF_TOKEN;const ENDPOINT_URL = import.meta.env.VITE_HF_FLUX2_DEV_ENDPOINT_URL;export const generateWithFlux2Dev = async (prompt: string,options?: {referenceImages?: string[];width?: number;height?: number;}): Promise<string> => {const hasRefs = options?.referenceImages && options.referenceImages.length > 0;const response = await fetch(ENDPOINT_URL, {method: 'POST',headers: {Authorization: `Bearer ${HF_TOKEN}`,'Content-Type': 'application/json'},body: JSON.stringify({inputs: prompt,parameters: {mode: hasRefs ? 'generate_with_refs' : 'generate',reference_images: options?.referenceImages,width: options?.width ?? 1920,height: options?.height ?? 1080,num_inference_steps: 50,guidance_scale: hasRefs ? 2.5 : 4.0,}})});const result = await response.json();return result.image;};```## Troubleshooting### Endpoint fails to start- Check HF_TOKEN has access to FLUX.2-dev (gated model)- Ensure GPU instance type has sufficient VRAM### Slow cold start- First inference after scale-up takes 2-3 minutes- Model loading + torch.compile warmup is cached### Out of memory12345678910111213141516171819202122232425262728293031323325 unmodified lines596061626364659 unmodified lines75767778798081828384858687888968 unmodified lines158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189# FLUX.2-dev Handler for HuggingFace Dedicated EndpointsImage generation using FLUX.2-dev with Remote Text Encoding for HuggingFace Dedicated Endpoints.## ArchitectureThis handler uses **Remote Text Encoding** to work around PyTorch version limitations on HuggingFace Inference Endpoints:- HF Endpoints runtime: PyTorch 2.2.0, transformers 4.48.0- FLUX.2 Mistral3 text encoder requires: transformers 4.52+ (PyTorch 2.6+)- Solution: Use HuggingFace's remote text encoding APIBenefits:- Saves ~24GB VRAM (no local Mistral3 text encoder)- Works with HF Endpoints' PyTorch 2.2.0 runtime- BF16 precision for transformer and VAE## Features- Remote text encoding via HuggingFace API- Multi-reference image support (up to 10 images)- 1920x1080 output resolution by default## GPU Requirements| GPU | VRAM | Mode | Notes ||-----|------|------|-------|| H200 | 141GB | Full GPU | Recommended || H100 | 80GB | Full GPU | Good || A100 | 80GB | CPU offload | Minimum |## Deployment Steps25 unmodified lines# Commit and pushgit add .git commit -m "Add FLUX.2-dev handler with remote text encoding"git push```9 unmodified lines- **Scaling**: Min 0, Max 1 (scale-to-zero enabled)- **Scale-to-Zero Timeout**: 15 minutes4. Environment Variables:- `HF_TOKEN`: Your HuggingFace token (REQUIRED - for model access AND remote text encoding)- `NUM_INFERENCE_STEPS`: `50` (optional, default is 50)5. Click "Create Endpoint"### 4. Wait for DeploymentFirst deployment takes 5-10 minutes to:- Download FLUX.2-dev transformer and VAE (~35GB without text encoder)- Test remote text encoding connection### 5. Test the Endpoint68 unmodified lines| Variable | Default | Description ||----------|---------|-------------|| `HF_TOKEN` | - | HuggingFace token (REQUIRED for model access and remote text encoding) || `NUM_INFERENCE_STEPS` | `50` | Default inference steps |Note: Unlike the Runpod version, this handler does NOT support FP8 quantization or torch.compile due to HF Endpoints' PyTorch 2.2.0 runtime.## Troubleshooting### Endpoint fails to start- Check HF_TOKEN has access to FLUX.2-dev (gated model)- Ensure HF_TOKEN is valid for remote text encoding API- Ensure GPU instance type has sufficient VRAM (80GB+)### "module 'torch' has no attribute 'int1'" errorThis means transformers was upgraded beyond what's compatible with PyTorch 2.2.0. Do NOT add `transformers>=4.47.0` to requirements.txt.### Remote text encoding fails- Verify HF_TOKEN is set and valid- Check network connectivity to `remote-text-encoder-flux-2.huggingface.co`### Slow cold start- First inference after scale-up takes 2-3 minutes- Model loading is the main bottleneck### Out of memory
README.md+41-103