add native hf auth check

Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
Vladimir Mandic
2025-04-13 10:05:15 -04:00
parent e9a31a92c9
commit 94848cbc2b
2 changed files with 26 additions and 19 deletions
+23 -19
View File
@@ -21,6 +21,13 @@ 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
try:
auth_check(shared.opts.model_h1_llama_repo)
except Exception as e:
shared.log.error(f'Load model: type=HiDream te4="{shared.opts.model_h1_llama_repo}" login={login} {e}')
return False
load_args, quant_args = model_quant.get_dit_args(diffusers_load_config, module='Transformer', device_map=True)
shared.log.debug(f'Load model: type=HiDream transformer="{repo_id}" quant="{model_quant.get_quant_type(quant_args)}" args={load_args}')
transformer = diffusers.HiDreamImageTransformer2DModel.from_pretrained(
@@ -47,25 +54,22 @@ def load_hidream(checkpoint_info, diffusers_load_config={}):
load_args, quant_args = model_quant.get_dit_args(diffusers_load_config, module='LLM', device_map=True)
shared.log.debug(f'Load model: type=HiDream te4="{shared.opts.model_h1_llama_repo}" quant="{model_quant.get_quant_type(quant_args)}" args={load_args}')
try:
text_encoder_4 = transformers.LlamaForCausalLM.from_pretrained(
shared.opts.model_h1_llama_repo,
output_hidden_states=True,
output_attentions=True,
cache_dir=shared.opts.hfcache_dir,
**load_args,
**quant_args,
)
tokenizer_4 = transformers.PreTrainedTokenizerFast.from_pretrained(
shared.opts.model_h1_llama_repo,
cache_dir=shared.opts.hfcache_dir,
**load_args,
)
if shared.opts.diffusers_offload_mode != 'none':
text_encoder_4 = text_encoder_4.to(devices.cpu)
except Exception as e:
shared.log.error(f'Load model: type=HiDream te4="{shared.opts.model_h1_llama_repo}" {e}')
shared.log.warning(f'Load model: type=HiDream te4="{shared.opts.model_h1_llama_repo}" login={login} verify access to gated model')
text_encoder_4 = transformers.LlamaForCausalLM.from_pretrained(
shared.opts.model_h1_llama_repo,
output_hidden_states=True,
output_attentions=True,
cache_dir=shared.opts.hfcache_dir,
**load_args,
**quant_args,
)
tokenizer_4 = transformers.PreTrainedTokenizerFast.from_pretrained(
shared.opts.model_h1_llama_repo,
cache_dir=shared.opts.hfcache_dir,
**load_args,
)
if shared.opts.diffusers_offload_mode != 'none':
text_encoder_4 = text_encoder_4.to(devices.cpu)
load_args, _quant_args = model_quant.get_dit_args(diffusers_load_config, module='Model')
shared.log.debug(f'Load model: type=HiDream model="{checkpoint_info.name}" repo="{repo_id}" offload={shared.opts.diffusers_offload_mode} dtype={devices.dtype} args={load_args}')
+3
View File
@@ -549,6 +549,9 @@ def load_diffuser(checkpoint_info=None, already_loaded_state_dict=None, timer=No
# load with custom loader
if sd_model is None:
sd_model = load_diffuser_force(model_type, checkpoint_info, diffusers_load_config, op)
if sd_model is not None and not sd_model:
shared.log.error(f'Load {op}: type="{model_type}" pipeline="{pipeline}" not loaded')
return
# load from hf folder-style
if sd_model is None: