rlightning.utils.utils¶
General utility functions and classes for RLightning.
This module provides utility functions for device handling, type conversions, and internal flags for controlling runtime behavior.
- class rlightning.utils.utils.InternalFlag[source]¶
Bases:
objectDynamic access to internal runtime flags.
Provides class-level properties to check various runtime modes controlled by environment variables.
Example
>>> if InternalFlag.DEBUG: ... # do something related with profiling and debugging ... pass
- rlightning.utils.utils.to_device(data: Any, device: str | MockModule('torch.device')) Any[source]¶
Move tensors in data structure to specified device.
Recursively traverses the data structure and moves any Tensor or TensorDict objects to the specified device.
- Parameters:
data – Any data structure that may contain Tensor or TensorDict.
device – Target device (e.g., ‘cpu’, ‘cuda:0’).
- Returns:
Data structure with tensors moved to the specified device.
- rlightning.utils.utils.to_numpy(data: Any) Any[source]¶
Convert tensors in data structure to NumPy arrays.
Recursively traverses the data structure and converts any Tensor objects to NumPy arrays.
- Parameters:
data – Any data structure that may contain Tensor objects.
- Returns:
Data structure with tensors converted to NumPy arrays.
- rlightning.utils.utils.torch_dtype_from_precision(precision: int | str | None) MockModule('torch.dtype') | None[source]¶
Convert precision specification to torch dtype.
- Parameters:
precision – Precision specification (int, str, or None).
- Returns:
Corresponding torch dtype, or None if precision is None.
- Raises:
ValueError – If precision cannot be parsed to a valid dtype.