ExternalModuleConfig#
Note
All Configs are derived from rastervision.pipeline.config.Config
, which itself is a pydantic Model.
- pydantic model ExternalModuleConfig[source]#
Config describing an object to be loaded via Torch Hub.
Show JSON schema
{ "title": "ExternalModuleConfig", "description": "Config describing an object to be loaded via Torch Hub.", "type": "object", "properties": { "uri": { "anyOf": [ { "minLength": 1, "type": "string" }, { "type": "null" } ], "default": null, "description": "Local uri of a zip file, or local uri of a directory,or remote uri of zip file.", "title": "Uri" }, "github_repo": { "anyOf": [ { "pattern": ".+/.+", "type": "string" }, { "type": "null" } ], "default": null, "description": "<repo-owner>/<repo-name>[:tag]", "title": "Github Repo" }, "name": { "anyOf": [ { "minLength": 1, "type": "string" }, { "type": "null" } ], "default": null, "description": "Name of the folder in which to extract/copy the definition files.", "title": "Name" }, "entrypoint": { "description": "Name of a Callable present in ``hubconf.py``. See docs for ``torch.hub`` for details.", "minLength": 1, "title": "Entrypoint", "type": "string" }, "entrypoint_args": { "default": [], "description": "Args to pass to the entrypoint. Must be serializable.", "items": {}, "title": "Entrypoint Args", "type": "array" }, "entrypoint_kwargs": { "default": {}, "description": "Keyword args to pass to the entrypoint. Must be serializable.", "title": "Entrypoint Kwargs", "type": "object" }, "force_reload": { "default": false, "description": "Force reload of module definition.", "title": "Force Reload", "type": "boolean" }, "type_hint": { "const": "external-module", "default": "external-module", "enum": [ "external-module" ], "title": "Type Hint", "type": "string" } }, "additionalProperties": false, "required": [ "entrypoint" ] }
- Config:
extra: str = forbid
validate_assignment: bool = True
- Fields:
- Validators:
check_either_uri_or_repo
»all fields
- field entrypoint: NonEmptyStr [Required]#
Name of a Callable present in
hubconf.py
. See docs fortorch.hub
for details.- Constraints:
strip_whitespace = True
min_length = 1
- Validated by:
- field entrypoint_args: list = []#
Args to pass to the entrypoint. Must be serializable.
- Validated by:
- field entrypoint_kwargs: dict = {}#
Keyword args to pass to the entrypoint. Must be serializable.
- Validated by:
- field github_repo: Annotated[str, StringConstraints(strip_whitespace=True, pattern='.+/.+')] | None = None#
<repo-owner>/<repo-name>[:tag]
- Validated by:
- field name: NonEmptyStr | None = None#
Name of the folder in which to extract/copy the definition files.
- Validated by:
- field uri: NonEmptyStr | None = None#
Local uri of a zip file, or local uri of a directory,or remote uri of zip file.
- Validated by:
- build(save_dir: str, hubconf_dir: str | None = None, ddp_rank: int | None = None) Any [source]#
Load an external module via torch.hub.
Note: Loading a PyTorch module is the typical use case, but there are no type restrictions on the object loaded through torch.hub.
- Parameters:
- Returns:
The module loaded via torch.hub.
- Return type:
- classmethod deserialize(inp: str | dict | Config) Self #
Deserialize Config from a JSON file or dict, upgrading if possible.
If
inp
is already aConfig
, it is returned as is.
- classmethod from_dict(cfg_dict: dict) Self #
Deserialize Config from a dict.
- Parameters:
cfg_dict (dict) – Dict to deserialize.
- Return type:
Self
- classmethod from_file(uri: str) Self #
Deserialize Config from a JSON file, upgrading if possible.
- Parameters:
uri (str) – URI to load from.
- Return type:
Self
- recursive_validate_config()#
Recursively validate hierarchies of Configs.
This uses reflection to call validate_config on a hierarchy of Configs using a depth-first pre-order traversal.
- revalidate()#
Re-validate an instantiated Config.
Runs all Pydantic validators plus self.validate_config().
- to_file(uri: str, with_rv_metadata: bool = True) None #
Save a Config to a JSON file, optionally with RV metadata.
- update(*args, **kwargs)#
Update any fields before validation.
Subclasses should override this to provide complex default behavior, for example, setting default values as a function of the values of other fields. The arguments to this method will vary depending on the type of Config.
- validate_config()#
Validate fields that should be checked after update is called.
This is to complement the builtin validation that Pydantic performs at the time of object construction.