MCPcopy
hub / github.com/mosaicml/composer / from_input

Method from_input

composer/core/time.py:391–421  ·  view source on GitHub ↗

Parse a time input into a :class:`Time` instance. Args: i (str | int | Time): The time input. default_int_unit (TimeUnit, optional): The default unit to use if ``i`` is an integer >>> Time.from_input("5ep") Time(5, TimeUnit.EPOCH) >>> Time.fr

(
        cls,
        i: Union[str, int, float, 'Time'],
        default_int_unit: Optional[Union[TimeUnit, str]] = None,
    )

Source from the content-addressed store, hash-verified

389
390 @classmethod
391 def from_input(
392 cls,
393 i: Union[str, int, float, 'Time'],
394 default_int_unit: Optional[Union[TimeUnit, str]] = None,
395 ) -> Time:
396 """Parse a time input into a :class:`Time` instance.
397
398 Args:
399 i (str | int | Time): The time input.
400 default_int_unit (TimeUnit, optional): The default unit to use if ``i`` is an integer
401
402 >>> Time.from_input("5ep")
403 Time(5, TimeUnit.EPOCH)
404 >>> Time.from_input(5, TimeUnit.EPOCH)
405 Time(5, TimeUnit.EPOCH)
406
407 Returns:
408 Time: An instance of :class:`Time`.
409 """
410 if isinstance(i, Time):
411 return i
412
413 if isinstance(i, str):
414 return Time.from_timestring(i)
415
416 if isinstance(i, int) or isinstance(i, float):
417 if default_int_unit is None:
418 raise RuntimeError('default_int_unit must be specified when constructing Time from an integer.')
419 return Time(i, default_int_unit)
420
421 raise RuntimeError(f'Cannot convert type {i} to {cls.__name__}')
422
423 @classmethod
424 def from_timestring(cls, timestring: str) -> Time:

Callers 13

__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80
stop_trainingMethod · 0.80
_parseMethod · 0.80
__init__Method · 0.80
epoch_in_iterationMethod · 0.80
ensure_timeFunction · 0.80
__init__Method · 0.80
__init__Method · 0.80
test_time_from_inputFunction · 0.80

Calls 2

TimeClass · 0.85
from_timestringMethod · 0.80

Tested by 2

test_time_from_inputFunction · 0.64