MCPcopy Create free account
hub / github.com/AlayaLab/Hive / _get_model_file

Function _get_model_file

models/flowsep/diffusers/utils/hub_utils.py:246–361  ·  view source on GitHub ↗
(
    pretrained_model_name_or_path,
    *,
    weights_name,
    subfolder,
    cache_dir,
    force_download,
    proxies,
    resume_download,
    local_files_only,
    use_auth_token,
    user_agent,
    revision,
    commit_hash=None,
)

Source from the content-addressed store, hash-verified

244
245
246def _get_model_file(
247 pretrained_model_name_or_path,
248 *,
249 weights_name,
250 subfolder,
251 cache_dir,
252 force_download,
253 proxies,
254 resume_download,
255 local_files_only,
256 use_auth_token,
257 user_agent,
258 revision,
259 commit_hash=None,
260):
261 pretrained_model_name_or_path = str(pretrained_model_name_or_path)
262 if os.path.isfile(pretrained_model_name_or_path):
263 return pretrained_model_name_or_path
264 elif os.path.isdir(pretrained_model_name_or_path):
265 if os.path.isfile(os.path.join(pretrained_model_name_or_path, weights_name)):
266 # Load from a PyTorch checkpoint
267 model_file = os.path.join(pretrained_model_name_or_path, weights_name)
268 return model_file
269 elif subfolder is not None and os.path.isfile(
270 os.path.join(pretrained_model_name_or_path, subfolder, weights_name)
271 ):
272 model_file = os.path.join(pretrained_model_name_or_path, subfolder, weights_name)
273 return model_file
274 else:
275 raise EnvironmentError(
276 f"Error no file named {weights_name} found in directory {pretrained_model_name_or_path}."
277 )
278 else:
279 # 1. First check if deprecated way of loading from branches is used
280 if (
281 revision in DEPRECATED_REVISION_ARGS
282 and (weights_name == WEIGHTS_NAME or weights_name == SAFETENSORS_WEIGHTS_NAME)
283 and version.parse(version.parse(__version__).base_version) >= version.parse("0.18.0")
284 ):
285 try:
286 model_file = hf_hub_download(
287 pretrained_model_name_or_path,
288 filename=_add_variant(weights_name, revision),
289 cache_dir=cache_dir,
290 force_download=force_download,
291 proxies=proxies,
292 resume_download=resume_download,
293 local_files_only=local_files_only,
294 use_auth_token=use_auth_token,
295 user_agent=user_agent,
296 subfolder=subfolder,
297 revision=revision or commit_hash,
298 )
299 warnings.warn(
300 f"Loading the variant {revision} from {pretrained_model_name_or_path} via `revision='{revision}'` is deprecated. Loading instead from `revision='main'` with `variant={revision}`. Loading model variants via `revision='{revision}'` will be removed in diffusers v1. Please use `variant='{revision}'` instead.",
301 FutureWarning,
302 )
303 return model_file

Callers 5

load_attn_procsMethod · 0.85
load_lora_weightsMethod · 0.85
from_pretrainedMethod · 0.85

Calls 1

_add_variantFunction · 0.85

Tested by

no test coverage detected