Time#
- class composer.Time(value, unit)[source]#
Time represents static durations of training time in terms of a
TimeUnitenum.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
TimeUnitenum 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:
Timesupports addition and subtraction with otherTimeinstances that share the sameTimeUnit. For example:>>> Time(1, TimeUnit.EPOCH) + Time(2, TimeUnit.EPOCH) Time(3, TimeUnit.EPOCH)
Timesupports 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)
Timesupports division. If the divisor is an instance ofTime, then it must have the same units as the dividend, and the result has units ofTimeUnit.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
Timewith units ofTimeUnit.BATCH.Equivalent to
Time(batch, TimeUnit.BATCH).
- classmethod from_duration(duration)[source]#
Create a
Timewith units ofTimeUnit.DURATION.Equivalent to
Time(duration, TimeUnit.DURATION).
- classmethod from_epoch(epoch)[source]#
Create a
Timewith units ofTimeUnit.EPOCH.Equivalent to
Time(epoch, TimeUnit.EPOCH).
- classmethod from_sample(sample)[source]#
Create a
Timewith units ofTimeUnit.SAMPLE.Equivalent to
Time(sample, TimeUnit.SAMPLE).
- classmethod from_timestring(timestring)[source]#
Parse a time string into a
Timeinstance.A time string is a numerical value followed by the value of a
TimeUnitenum. 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
Timewith units ofTimeUnit.TOKEN.Equivalent to
Time(sample, TimeUnit.TOKEN).
- to_timestring()[source]#
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.