From d3203253ad565d04a814e14f4ead352a4d6633a4 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Fri, 18 Apr 2025 17:22:05 -0400 Subject: [PATCH] add hf auth checks for flux and sd35 Signed-off-by: Vladimir Mandic --- CHANGELOG.md | 4 ++-- modules/mit_nunchaku.py | 2 +- modules/model_flux.py | 12 +++++++++--- modules/model_hidream.py | 9 ++++----- modules/model_sd3.py | 10 +++++++++- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b831d65e7..12d233b00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ highly experimental and with limited support, but when it works, its magic: **Flux.1 at 6.0 it/s** *(not sec/it)*! see [Nunchaku Wiki](https://github.com/vladmandic/sdnext/wiki/Nunchaku) for installation guide and list of supported models & features - [LTXVideo 0.9.6](https://github.com/Lightricks/LTX-Video?tab=readme-ov-file) T2V and I2V - in both standard and distilled variants + in both **Standard** and **Distilled** variants - [CFG-Zero](https://github.com/WeichenFan/CFG-Zero-star) new guidance method optimized for flow-matching models implemented for **FLUX.1, HiDream-I1, SD3.x, CogView4, HunyuanVideo, WanAI** enable and configure in *settings -> pipeline modifiers -> cfg zero* @@ -20,7 +20,7 @@ - add explicit offload after encode prompt configure in *settings -> text encoder -> offload* - **Other** - - **HiDream** add HF gated access auth check + - **HiDream-I1, FLUX.1, SD3.x** add HF gated access auth check - **HiDream** add LLM into to metadata - add **UniPC FlowMatch** scheduler - add **LCM FlowMatch** scheduler diff --git a/modules/mit_nunchaku.py b/modules/mit_nunchaku.py index 39497cf36..9e421d377 100644 --- a/modules/mit_nunchaku.py +++ b/modules/mit_nunchaku.py @@ -44,7 +44,7 @@ def install_nunchaku(): arch = platform.system().lower() if arch not in ['linux', 'windows']: log.error(f'Nunchaku: platform={arch} unsupported') - return + return False if devices.backend not in ['cuda']: log.error(f'Nunchaku: backend={devices.backend} unsupported') return False diff --git a/modules/model_flux.py b/modules/model_flux.py index eabb248f7..17ebe06c7 100644 --- a/modules/model_flux.py +++ b/modules/model_flux.py @@ -4,7 +4,7 @@ import torch import diffusers import transformers from safetensors.torch import load_file -from huggingface_hub import hf_hub_download +from huggingface_hub import hf_hub_download, auth_check from modules import shared, errors, devices, modelloader, sd_models, sd_unet, model_te, model_quant, sd_hijack_te @@ -202,11 +202,17 @@ def load_transformer(file_path): # triggered by opts.sd_unet change def load_flux(checkpoint_info, diffusers_load_config): # triggered by opts.sd_checkpoint change - prequantized = model_quant.get_quant(checkpoint_info.path) repo_id = sd_models.path_to_repo(checkpoint_info.name) + login = modelloader.hf_login() + try: + auth_check(repo_id) + except Exception as e: + shared.log.error(f'Load model: repo="{repo_id}" login={login} {e}') + return False + + prequantized = model_quant.get_quant(checkpoint_info.path) shared.log.debug(f'Load model: type=FLUX model="{checkpoint_info.name}" repo="{repo_id}" unet="{shared.opts.sd_unet}" te="{shared.opts.sd_text_encoder}" vae="{shared.opts.sd_vae}" quant={prequantized} offload={shared.opts.diffusers_offload_mode} dtype={devices.dtype}') debug(f'Load model: type=FLUX config={diffusers_load_config}') - modelloader.hf_login() transformer = None text_encoder_1 = None diff --git a/modules/model_hidream.py b/modules/model_hidream.py index 948cc6c85..110a32bdb 100644 --- a/modules/model_hidream.py +++ b/modules/model_hidream.py @@ -1,6 +1,7 @@ import os import transformers import diffusers +from huggingface_hub import auth_check from modules import shared, devices, sd_models, model_quant, modelloader, sd_hijack_te @@ -76,14 +77,12 @@ def load_text_encoders(repo_id, diffusers_load_config={}): def load_hidream(checkpoint_info, diffusers_load_config={}): - login = modelloader.hf_login() repo_id = sd_models.path_to_repo(checkpoint_info.name) - - from huggingface_hub import auth_check + login = modelloader.hf_login() try: - auth_check(shared.opts.model_h1_llama_repo) + auth_check(repo_id) except Exception as e: - shared.log.error(f'Load model: type=HiDream te4="{shared.opts.model_h1_llama_repo}" login={login} {e}') + shared.log.error(f'Load model: repo="{repo_id}" login={login} {e}') return False transformer = load_transformer(repo_id, diffusers_load_config) diff --git a/modules/model_sd3.py b/modules/model_sd3.py index c2ac92143..ecfc533a1 100644 --- a/modules/model_sd3.py +++ b/modules/model_sd3.py @@ -1,7 +1,8 @@ import os import diffusers import transformers -from modules import shared, devices, errors, sd_models, sd_unet, model_quant, model_tools +from huggingface_hub import auth_check +from modules import shared, devices, errors, sd_models, sd_unet, model_quant, model_tools, modelloader def load_overrides(kwargs, cache_dir): @@ -90,6 +91,13 @@ def load_missing(kwargs, fn, cache_dir): def load_sd3(checkpoint_info, cache_dir=None, config=None): repo_id = sd_models.path_to_repo(checkpoint_info.name) + login = modelloader.hf_login() + try: + auth_check(repo_id) + except Exception as e: + shared.log.error(f'Load model: repo="{repo_id}" login={login} {e}') + return False + fn = checkpoint_info.path kwargs = {}