emmi_inference.api

Functions

load_yaml(path)

Reads a YAML file and returns a dictionary.

run_inference_from_config(config_path, model_type, ...)

Run inference based on the input config and the provided arguments.

setup_environment(device, autocast, dtype)

Resolves device, dtype and autocast settings.

load_components(config, model_type, model_path, ...)

Instantiates and returns the core components like Runner, Dataset, etc.

create_writer(config_params, cli_destination, ...)

Determines the final destination and instantiates the correct

process_dataset_sample_by_sample(*, runner, dataset, ...)

Executes inference over the input dataset.

run_post_upload(is_remote, upload_mode, ...)

Uploads local data from the local_spool_dir to final_destination via S3FileUploader.

Module Contents

emmi_inference.api.load_yaml(path)

Reads a YAML file and returns a dictionary.

Parameters:

path (pathlib.Path) – The path to the YAML file.

Returns:

  • Dictionary mapping keys to values.

Return type:

dict[str, Any]

emmi_inference.api.run_inference_from_config(config_path, model_type, model_path, destination, device=DeviceEnum.AUTO, autocast=False, dtype=None, upload_mode=UploadMode.SPOOL, remove_local_spool=False, upload_batch_size=100, upload_workers=8)

Run inference based on the input config and the provided arguments.

Parameters:
  • config_path (pathlib.Path) – Path to config file (YAML) to use.

  • model_type (str) – A string name of the model type to use.

  • model_path (pathlib.Path) – Path to the model checkpoint.

  • device (emmi_inference.device.DeviceEnum) – Device to use. Defaults to “auto”.

  • autocast (bool) – Either or not autocast to be enabled. Works only for CUDA. Defaults to False.

  • dtype (str | None) – Datatype to use. Defaults to None.

  • destination (str | None) – Output destination. Can be a local path (e.g., ‘./results’) or a remote URI (e.g., ‘s3://bucket/key’). If not set, uses ‘save_dir’ from the config file for local-only output.

  • upload_mode (emmi_inference.UploadMode) – Upload mode when destination is set. Defaults to ‘spool’.

  • remove_local_spool (bool) – Remove local spool/cache after successful upload.

  • upload_batch_size (int) – Batch size for ‘spool’ mode uploads.

  • upload_workers (int) – Number of parallel upload workers.

Return type:

None

emmi_inference.api.setup_environment(device, autocast, dtype)

Resolves device, dtype and autocast settings.

Parameters:
Returns:

Device string, dtype string or None, and autocast settings.

Return type:

tuple

emmi_inference.api.load_components(config, model_type, model_path, device_str, torch_dtype, effective_autocast)

Instantiates and returns the core components like Runner, Dataset, etc.

Parameters:
  • config (dict[str, Any]) – Inout configuration as a dictionary.

  • model_type (str) – A string name of the model type to use.

  • model_path (pathlib.Path) – Path to the model checkpoint.

  • device_str (str) – Device string to use, e.g. “cuda”.

  • torch_dtype (torch.dtype | None) – Datatype to use. Defaults to None.

  • effective_autocast (bool) – Either or not use autocast.

Returns:

an inference runner and a dataset.

Return type:

tuple

emmi_inference.api.create_writer(config_params, cli_destination, local_spool_dir, upload_mode, remove_local_spool, upload_workers, upload_batch_size)

Determines the final destination and instantiates the correct writer (AsyncWriter or S3SpoolingUploader).

Returns:

(writer_context, final_destination, is_remote_destination)

Parameters:
Return type:

tuple[emmi_inference.writer.AsyncWriter | emmi_inference.s3_spooling_uploader.S3SpoolingUploader, str, bool]

emmi_inference.api.process_dataset_sample_by_sample(*, runner, dataset, writer, batch_simplification, batch_keys_to_drop, batch_keys_to_keep)

Executes inference over the input dataset. Even though this method doesn’t raise exceptions directly it may log errors and raise uncaught exceptions.

Parameters:
Return type:

None

emmi_inference.api.run_post_upload(is_remote, upload_mode, local_spool_dir, final_destination, upload_workers, remove_local_spool)

Uploads local data from the local_spool_dir to final_destination via S3FileUploader. This method is executed _after_ the inference is done and is valid for S3 uploads only.

Parameters:
  • is_remote (bool) – Either the target is remote or local. If False - there will be no upload.

  • upload_mode (emmi_inference.UploadMode) – Upload mode to use. If anything but “after” - there will be no upload.

  • local_spool_dir (pathlib.Path) – Local Spooling directory.

  • final_destination (str) – Desired final destination.

  • upload_workers (int) – Number of worker processes to use.

  • remove_local_spool (bool) – Whether to remove the local spool directory after upload.

Return type:

None