MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / load

Function load

python/oneflow/hub.py:535–631  ·  view source on GitHub ↗

Load a model from a github repo or a local directory. Note: Loading a model is the typical use case, but this can also be used to for loading other objects such as tokenizers, loss functions, etc. If ``source`` is 'github', ``repo_or_dir`` is expected to be of the form ``repo_ow

(
    repo_or_dir,
    model,
    *args,
    source="github",
    trust_repo=None,
    force_reload=False,
    verbose=True,
    skip_validation=False,
    **kwargs,
)

Source from the content-addressed store, hash-verified

533
534
535def load(
536 repo_or_dir,
537 model,
538 *args,
539 source="github",
540 trust_repo=None,
541 force_reload=False,
542 verbose=True,
543 skip_validation=False,
544 **kwargs,
545):
546 """
547 Load a model from a github repo or a local directory.
548 Note: Loading a model is the typical use case, but this can also be used to
549 for loading other objects such as tokenizers, loss functions, etc.
550 If ``source`` is 'github', ``repo_or_dir`` is expected to be
551 of the form ``repo_owner/repo_name[:ref]`` with an optional
552 ref (a tag or a branch).
553 If ``source`` is 'local', ``repo_or_dir`` is expected to be a
554 path to a local directory.
555
556 Args:
557 repo_or_dir (str): If ``source`` is 'github',
558 this should correspond to a github repo with format ``repo_owner/repo_name[:ref]`` with
559 an optional ref (tag or branch), for example 'Oneflow-Inc/vision:0.2.0'. If ``ref`` is not specified,
560 the default branch is assumed to be ``main`` if it exists, and otherwise ``master``.
561 If ``source`` is 'local' then it should be a path to a local directory.
562 model (str): the name of a callable (entrypoint) defined in the
563 repo/dir's ``hubconf.py``.
564 *args (optional): the corresponding args for callable ``model``.
565 source (str, optional): 'github' or 'local'. Specifies how
566 ``repo_or_dir`` is to be interpreted. Default is 'github'.
567 trust_repo (bool, str or None): ``"check"``, ``True``, ``False`` or ``None``.
568 This parameter was introduced in v1.12 and helps ensuring that users
569 only run code from repos that they trust.
570
571 - If ``False``, a prompt will ask the user whether the repo should
572 be trusted.
573
574 - If ``True``, the repo will be added to the trusted list and loaded
575 without requiring explicit confirmation.
576
577 - If ``"check"``, the repo will be checked against the list of
578 trusted repos in the cache. If it is not present in that list, the
579 behaviour will fall back onto the ``trust_repo=False`` option.
580
581 - If ``None``: this will raise a warning, inviting the user to set
582 ``trust_repo`` to either ``False``, ``True`` or ``"check"``. This
583 is only present for backward compatibility and will be removed in
584 v1.14.
585
586 Default is ``None`` and will eventually change to ``"check"`` in v1.14.
587 force_reload (bool, optional): whether to force a fresh download of
588 the github repo unconditionally. Does not have any effect if
589 ``source = 'local'``. Default is ``False``.
590 verbose (bool, optional): If ``False``, mute messages about hitting
591 local caches. Note that the message about first download cannot be
592 muted. Does not have any effect if ``source = 'local'``.

Callers

nothing calls this directly

Calls 3

_get_cache_or_reloadFunction · 0.85
_load_localFunction · 0.85
lowerMethod · 0.45

Tested by

no test coverage detected