DataSpec (original) (raw)

Back to top

Edit this page

Toggle table of contents sidebar

class composer.DataSpec(dataloader, num_samples=None, num_tokens=None, device_transforms=None, split_batch=None, get_num_samples_in_batch=None, get_num_tokens_in_batch=None)[source]#

Specifications for operating and training on data.

An example of constructing a DataSpec object with a device_transformscallable and then using it with Trainer:

Construct DataSpec and subtract mean from the batch

device_transform_fn = lambda xs, ys: (xs.sub_(xs.mean()), ys) train_dspec = DataSpec(train_dataloader, device_transforms=device_transform_fn)

The same function can be used for eval dataloader as well

eval_dspec = DataSpec(eval_dataloader, device_transforms=device_transform_fn)

Use this DataSpec object to construct trainer

trainer = Trainer( ... model=model, ... train_dataloader=train_dspec, ... eval_dataloader=eval_dspec, ... optimizers=optimizer, ... max_duration="1ep", ... )

Parameters