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:
field entrypoint: NonEmptyStr [Required]#

Name of a Callable present in hubconf.py. See docs for torch.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 force_reload: bool = False#

Force reload of module definition.

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 type_hint: Literal['external-module'] = 'external-module'#
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:
  • save_dir (str) – The module def will be saved here.

  • hubconf_dir (str) – Path to existing definition. If provided, the definition will not be fetched from the external source but instead from this dir. Defaults to None.

  • ddp_rank (int | None) –

Returns:

The module loaded via torch.hub.

Return type:

Any

validator check_either_uri_or_repo  »  all fields[source]#
Return type:

Self

classmethod deserialize(inp: str | dict | Config) Self#

Deserialize Config from a JSON file or dict, upgrading if possible.

If inp is already a Config, it is returned as is.

Parameters:

inp (str | dict | Config) – a URI to a JSON file or a dict.

Return type:

Self

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.

Parameters:
  • uri (str) – URI to save to.

  • with_rv_metadata (bool) – If True, inject Raster Vision metadata such as plugin_versions, so that the config can be upgraded when loaded.

Return type:

None

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.

validate_list(field: str, valid_options: list[str])#

Validate a list field.

Parameters:
  • field (str) – name of field to validate

  • valid_options (list[str]) – values that field is allowed to take

Raises:

ConfigError – if field is invalid