utils#
Module attributes and functions#
- utils.check_fn_dynamic_type(fn, tp, strict=True)[source]#
Controls if the function respects the type tp. The function must have the same number of arguments as the type tp and the same type for each argument.
- utils.create_if_not_exists(path)[source]#
Creates the specified folder if it does not exist.
- Parameters:
path (str) – the complete path of the folder to be created
- class utils.disable_logging(min_level=50)[source]#
Wrapper for disabling logging for a specific block of code.
- utils.field_with_aliases(choices)[source]#
Build a data type where for each key in choices there are a set of aliases.
Example
Given the following dictionary:
choices = { 'a': ['a', 'alpha'], 'b': ['b', 'beta'] }
The values ‘a’ and ‘alpha’ will be converted to ‘a’, and ‘b’ and ‘beta’ will be converted to ‘b’.
- utils.infer_args_from_signature(signature, excluded_signature=None, ignore_args=None)[source]#
Load the arguments of a function from its signature.
- Parameters:
- Return type:
This function will return a dictionary with the arguments of the function, their type, and whether they are required or not. If an argument has a default value, it will be included in the dictionary as well.
- Returns:
the inferred arguments
- Return type:
- utils.random_id(length=8, alphabet='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')[source]#
Returns a random string of the specified length.
- Parameters:
length – the length of the string
alphabet – the alphabet to be used
- Returns:
the random string
- utils.register_dynamic_module_fn(name, register, tp, ignore_args=None)[source]#
Register a dynamic module in the specified dictionary.
- Parameters:
name (str) – the name of the module
register (dict) – the dictionary where the module will be registered
cls – the class to be registered
tp (Type[T]) – the type of the class, used to dynamically infer the arguments
ignore_args (list | None) – a list of arguments to be ignored when inferring the arguments from the signature
- Return type:
- utils.to_parsable_obj(r)[source]#
Convert a non-builtin object to a parsable (and loadable with weights_only=True) object. Looking at you, Namespace.