Time (original) (raw)
Toggle table of contents sidebar
class composer.Time(value, unit)[source]#
Time represents static durations of training time in terms of a TimeUnit enum.
See the Time Guide for more details on tracking time during training.
To construct an instance of Time, you can either:
- Use a value followed by a TimeUnit enum or string. For example,
Time(5, TimeUnit.EPOCH) # describes 5 epochs. Time(5, TimeUnit.EPOCH) Time(30_000, "tok") # describes 30,000 tokens. Time(30000, TimeUnit.TOKEN) Time(0.5, "dur") # describes 50% of the training process. Time(0.5, TimeUnit.DURATION)
- Use one of the helper methods. See:
- Time.from_epoch()
- Time.from_batch()
- Time.from_sample()
- Time.from_token()
- Time.from_duration()
- Time.from_timestring().
Time supports addition and subtraction with other Time instances that share the sameTimeUnit. For example:
Time(1, TimeUnit.EPOCH) + Time(2, TimeUnit.EPOCH) Time(3, TimeUnit.EPOCH)
Time supports multiplication. The multiplier must be either a number or have units ofTimeUnit.DURATION. The multiplicand is scaled, and its units are kept.
Time(2, TimeUnit.EPOCH) * 0.5 Time(1, TimeUnit.EPOCH)
Time(2, TimeUnit.EPOCH) * Time(0.5, TimeUnit.DURATION) Time(1, TimeUnit.EPOCH)
Time supports division. If the divisor is an instance of Time, then it must have the same units as the dividend, and the result has units of TimeUnit.DURATION. For example:
Time(4, TimeUnit.EPOCH) / Time(2, TimeUnit.EPOCH) Time(2.0, TimeUnit.DURATION)
If the divisor is number, then the dividend is scaled, and it keeps its units. For example:
Time(4, TimeUnit.EPOCH) / 2 Time(2, TimeUnit.EPOCH)
Parameters
classmethod from_batch(batch)[source]#
Create a Time with units of TimeUnit.BATCH.
Equivalent to Time(batch, TimeUnit.BATCH)
.
Parameters
batch (int) – Number of batches.
Returns
Time – Time instance, in batches.
classmethod from_duration(duration)[source]#
Create a Time with units of TimeUnit.DURATION.
Equivalent to Time(duration, TimeUnit.DURATION)
.
Parameters
duration (float) – Duration of the training process. Should be on [0, 1)
where 0
represents the beginning of the training process and 1
represents a completed training process.
Returns
Time – Time instance, in duration.
classmethod from_epoch(epoch)[source]#
Create a Time with units of TimeUnit.EPOCH.
Equivalent to Time(epoch, TimeUnit.EPOCH)
.
Parameters
epoch (int) – Number of epochs.
Returns
Time – Time instance, in epochs.
classmethod from_input(i, default_int_unit=None)[source]#
Parse a time input into a Time instance.
Parameters
- 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.from_input(5, TimeUnit.EPOCH) Time(5, TimeUnit.EPOCH)
Returns
Time – An instance of Time.
classmethod from_iteration(iteration)[source]#
Create a Time with units of TimeUnit.ITERATION.
Equivalent to Time(iteration, TimeUnit.ITERATION)
.
Parameters
iteration (int) – Number of iterations.
Returns
Time – Time instance, in iterations.
classmethod from_sample(sample)[source]#
Create a Time with units of TimeUnit.SAMPLE.
Equivalent to Time(sample, TimeUnit.SAMPLE)
.
Parameters
sample (int) – Number of samples.
Returns
Time – Time instance, in samples.
classmethod from_timedelta(timestring)[source]#
Create a Time with units of TimeUnit.SECOND
.
Equivalent to Time(batch, TimeUnit.SECOND)
.
Parameters
timestring (int) – timedelta string in _h_m_s.
Returns
Time – Time instance, in seconds.
classmethod from_timestring(timestring)[source]#
Parse a time string into a Time instance.
A time string is a numerical value followed by the value of a TimeUnit enum. For example:
Time.from_timestring("5ep") # describes 5 epochs. Time(5, TimeUnit.EPOCH) Time.from_timestring("3e4tok") # describes 30,000 tokens. Time(30000, TimeUnit.TOKEN) Time.from_timestring("0.5dur") # describes 50% of the training process. Time(0.5, TimeUnit.DURATION)
Returns
Time – An instance of Time.
classmethod from_token(token)[source]#
Create a Time with units of TimeUnit.TOKEN.
Equivalent to Time(sample, TimeUnit.TOKEN)
.
Parameters
token (int) – Number of tokens.
Returns
Time – Time instance, in tokens.
Get the time-string representation.
For example:
Time(5, TimeUnit.EPOCH).to_timestring() '5ep'
Returns
str – The time-string representation.
property unit#
The unit of the time.
property value#
The value of the time, as a number.