utils¶
- olmo_core.utils.get_default_thread_count()[source]¶
Get the default maximum number of threads allowed.
- Return type:
- olmo_core.utils.wait_for(condition, description, timeout=10.0)[source]¶
Wait for the condition function to return True.
- olmo_core.utils.apply_to_tensors(fn, container)[source]¶
Recursively apply
fnto all tensors in a container.- Return type:
- olmo_core.utils.move_to_device(o, device, non_blocking=None)[source]¶
Move a tensor or container of tensors to the given device.
- olmo_core.utils.mark_dynamic(x, dim, strict=True)[source]¶
Mark a tensor as having dynamic sizes for
torch.compile().
- olmo_core.utils.same_storage(x, y)[source]¶
Check if two tensors share the same storage.
- Return type:
- class olmo_core.utils.LogFilterType(value)[source]¶
Bases:
StrEnumDetermines which ranks are allowed to emit INFO messages.
- rank0_only = 'rank0_only'¶
INFO messages are only emitted from the global rank 0.
- local_rank0_only = 'local_rank0_only'¶
INFO messages are only emitted from the local (node) rank 0.
- all_ranks = 'all_ranks'¶
All ranks emit INFO messages.
- olmo_core.utils.log_extra_field(field_name, field_value)[source]¶
Add an additional field to each log record.
Note
For these fields to actually show up in the logs you need to use a formatter/handler that displays them.
- olmo_core.utils.setup_logging(log_filter_type='rank0_only', force=False)[source]¶
Configure logging.
See also
- Parameters:
log_filter_type (
LogFilterType, default:'rank0_only') – Which ranks emit INFO and below messages.force (
bool, default:False) – Force configuring logging even if it was already configured.
- Return type:
- olmo_core.utils.logging_configured()[source]¶
Returns
Trueif logging has been configured (like withsetup_logging()), otherwise returnsFalse.- Return type:
- olmo_core.utils.excepthook(exctype, value, traceback)[source]¶
Used to patch
sys.excepthookin order to log exceptions. Useinstall_excepthook()to install this.
- olmo_core.utils.install_excepthook()[source]¶
Install the custom
excepthook().See also
- olmo_core.utils.filter_warnings()[source]¶
Configure warning filters for warnings we don’t need to see.
See also
- olmo_core.utils.set_env_variables()[source]¶
Set common needed env vars if they’re not already set.
See also
- olmo_core.utils.prepare_cli_environment(log_filter_type=None)[source]¶
Prepare the environment for a script/CLI. This should be called at the very beginning of the script/command, like at the top of the
if __name__ == "__main__": ...block.Internally this calls:
Tip
If you’re looking to setup the environment specifically for distributed training, see
prepare_training_environment()instead.- Parameters:
log_filter_type (
Optional[LogFilterType], default:None) –Determines which ranks are allowed to emit log messages below the
WARNINGlevel. You can also configure this through the env varLOG_FILTER_TYPE. If neither are set, this defaults to “rank0_only”.Note
All ranks will always emit messages at the
WARNINGlevel or higher.
- olmo_core.utils.threaded_generator(g, maxsize=16, thread_name=None)[source]¶
Wraps a generator
gand runs it in a thread.
- olmo_core.utils.roundrobin(*iterables)[source]¶
Call the given iterables in a round-robin fashion. For example:
roundrobin('ABC', 'D', 'EF') --> A D E B F C
- olmo_core.utils.format_int(count)[source]¶
Format a large integer into a more human-readable string.
- Return type:
- olmo_core.utils.flatten_dict(d)[source]¶
Flatten a nested dictionary with strings keys using dot notation.
- olmo_core.utils.cuda_sync_debug_mode(debug_mode)[source]¶
A context manager for temporarily setting the CUDA sync debug mode.
- olmo_core.utils.get_element_size(dtype)[source]¶
Get the size in bytes of element of the given PyTorch dtype.
- Return type: