composer.utils#

Helper utilities.

Functions

batch_get

Indexes into the batch given the key.

batch_set

Indexes into the batch given the key and sets the element at that index to value.

configure_excepthook

Collect and print system information when sys.excepthook() is called.

convert_flat_dict_to_nested_dict

Converts flat dictionary separated by slashes to nested dictionary.

convert_nested_dict_to_flat_dict

Takes in a nested dict converts it to a flat dict with keys separated by slashes.

create_symlink_file

Create a symlink file, which can be followed by get_file().

disable_env_report

Disable environment report generation on exception.

enable_env_report

Enable environment report generation on exception.

ensure_folder_has_no_conflicting_files

Ensure that the given folder does not have any files conflicting with the filename format string.

ensure_folder_is_empty

Ensure that the given folder is empty.

ensure_tuple

Converts x into a tuple.

export_for_inference

Export a model for inference.

export_with_logger

Helper method for exporting a model for inference.

extract_hparams

Takes in local symbol table and recursively grabs any hyperparameter.

format_name_with_dist

Format format_str with the run_name, distributed variables, and extra_format_kwargs.

format_name_with_dist_and_time

Format format_str with the run_name, distributed variables, timestamp, and extra_format_kwargs.

get_composer_env_dict

Query Composer pertinent system information as a dict.

get_device

Takes string or Device and returns the corresponding Device.

get_file

Get a file from a local folder, URL, or object store.

get_free_tcp_port

Get free socket port to use as MASTER_PORT.

import_object

Dynamically import a Python object (e.g.

is_model_deepspeed

Whether model is an instance of a DeepSpeedEngine.

is_model_fsdp

Whether model is an instance of a FullyShardedDataParallel.

is_notebook

Whether Composer is running in a IPython/Jupyter Notebook.

is_tar

Returns whether name has a tar-like extension.

is_tpu_installed

Determines whether the module needed for training on TPUsโ€”torch_xlaโ€”is installed.

load_checkpoint

Load a checkpoint from a local file, URI, or cloud object store into state.

map_collection

Applies map_fn on each element in collection.

maybe_create_object_store_from_uri

Automatically creates an composer.utils.ObjectStore from supported URI formats.

maybe_create_remote_uploader_downloader_from_uri

Automatically creates a composer.loggers.RemoteUploaderDownloader from supported URI formats.

model_eval_mode

Set model.eval() for context duration, restoring model status at end.

parse_uri

Uses urllib.parse.urlparse() to parse the provided URI.

print_env

Generate system information report.

retry

Decorator to retry a function with backoff and jitter.

safe_torch_load

Load a torch checkpoint, catching errors due to backwards compatibility issues.

save_checkpoint

Checkpoint the training state.

using_torch_2

Check the PyTorch version and compared it with version 2.0.0.

Classes

ExportFormat

Enum class for the supported export formats.

IteratorFileStream

Class used to convert iterator of bytes into a file-like binary stream object.

LibcloudObjectStore

Utility for uploading to and downloading from object (blob) stores, such as Amazon S3.

OCIObjectStore

Utility for uploading to and downloading from an OCI bucket.

ObjectStore

Abstract class for implementing object stores, such as LibcloudObjectStore and S3ObjectStore.

PartialFilePath

S3ObjectStore

Utility for uploading to and downloading from an S3-compatible bucket using boto3.

SFTPObjectStore

Utility for uploading to and downloading to a server via SFTP.

StringEnum

Base class for Enums containing string values.

Exceptions

MissingConditionalImportError

Handles errors for external packages that might not be installed.

ObjectStoreTransientError

Custom exception class to signify transient errors.