colossalai.builder.builder

colossalai.builder.builder.build_from_config(module, config)

Returns an object of module constructed from config.

Parameters
  • module (class) – A python or user-defined class

  • config (dict) – A python dict containing information used in the construction of the return object

Raises

AssertionError – Raises an AssertionError if module is not a class

Returns

An object of interest

Return type

Object

colossalai.builder.builder.build_from_registry(config, registry)

Returns an object constructed from config, the type of the object is specified by registry.

Parameters
  • config (dict or colossalai.context.colossalai.context.Config) – A python dict or a colossalai.context.Config object containing information used in the construction of the return object

  • registry (Registry) – A registry specifying the type of the return object

Raises
  • AssertionError – Raises an AssertionError if registry is not an object of Registry or mod_type in config is not found in registry

  • Exception – Raises an Exception if an error occurred when building from registry

Returns

An object specified by registry

Return type

Python object specified by registry

colossalai.builder.builder.build_layer(config)

Returns a layer object of nn.Module constructed from config.

Parameters

config (dict or colossalai.context.Config) – A python dict or a colossalai.context.Config object containing information used in the construction of the return object

Returns

An object of torch.nn.Module

Return type

torch.nn.Module

colossalai.builder.builder.build_loss(config)

Returns a loss function object of torch.autograd.Function constructed from config.

Parameters

config (dict or colossalai.context.Config) – A python dict or a colossalai.context.Config object containing information used in the construction of the return object

Returns

An object of torch.nn.modules.loss._Loss

Return type

torch.nn.modules.loss._Loss

colossalai.builder.builder.build_model(config)

Returns a model object of nn.Module constructed from config.

Parameters

config (dict or colossalai.context.Config) – A python dict or a colossalai.context.Config object containing information used in the construction of the return object

Returns

An object of torch.nn.Module

Return type

torch.nn.Module

colossalai.builder.builder.build_dataset(config)

Returns a dataset object of torch.utils.data.Dataset constructed from config.

Parameters

config (dict or colossalai.context.Config) – A python dict or a colossalai.context.Config object containing information used in the construction of the return object

Returns

An object of torch.utils.data.Dataset

Return type

torch.utils.data.Dataset

colossalai.builder.builder.build_optimizer(config, model)

Returns an optimizer object of torch.optim.Optimizer constructed from config, ‘model’ and ‘params’.

Parameters
  • config (dict or colossalai.context.Config) – A python dict or a colossalai.context.Config object containing information used in the construction of the return object

  • model (nn.Module) – A model containing parameters for the optimizer

Returns

An object of torch.optim.Optimizer

Return type

torch.optim.Optimizer

colossalai.builder.builder.build_gradient_handler(config, model, optimizer)

Returns a gradient handler object of BaseGradientHandler constructed from config, model and optimizer.

Parameters
  • config (dict or colossalai.context.Config) – A python dict or a colossalai.context.Config object containing information used in the construction of the return object

  • model (nn.Module) – A model containing parameters for the gradient handler

  • optimizer (torch.optim.Optimizer) – An optimizer object containing parameters for the gradient handler

Returns

An object of colossalai.engine.BaseGradientHandler

Return type

colossalai.engine.BaseGradientHandler

colossalai.builder.builder.build_hooks(config, trainer)

Returns a hook object of BaseHook constructed from config and trainer.

Parameters
  • config (dict or colossalai.context.Config) – A python dict or a colossalai.context.Config object containing information used in the construction of the return object

  • trainer (Trainer) – A Trainer object containing parameters for the hook

Returns

An object of colossalai.trainer.hooks.BaseHook

Return type

colossalai.trainer.hooks.BaseHook

colossalai.builder.builder.build_ophooks(config)

Returns a hook object of BaseOpHook constructed from config.

Parameters

config (dict or colossalai.context.Config) – A python dict or a colossalai.context.Config object containing information used in the construction of the return object

Returns

An object of colossalai.trainer.hooks.BaseOpHook

Return type

colossalai.trainer.hooks.BaseOpHook

colossalai.builder.builder.build_transform(config)

Returns a transformation object of torchvision.transforms constructed from config.

Parameters

config (dict or colossalai.context.Config) – A python dict or a colossalai.context.Config object containing information used in the construction of the return object

Returns

An object of torchvision.transforms

Return type

torchvision.transforms

colossalai.builder.builder.build_data_sampler(config, dataset)

Returns a data sampler object of colossalai.nn.data.sampler.BaseSampler constructed from config.

Parameters
  • config (dict or colossalai.context.Config) – A python dict or a colossalai.context.Config object containing information used in the construction of the return object

  • dataset (torch.utils.data.Dataset) – An object of torch.utils.data.Dataset containing information used in the construction of the return object

Returns

An object of colossalai.utils.data_sampler.BaseSampler

Return type

colossalai.utils.data_sampler.BaseSampler

colossalai.builder.builder.build_lr_scheduler(config, optimizer)

Returns a learning rate scheduler object of torch.optim.lr_scheduler constructed from config, optimizer, total_steps and num_steps_per_epoch.

Parameters
  • config (dict or colossalai.context.Config) – A python dict or a colossalai.context.Config object containing information used in the construction of the return object

  • optimizer (torch.optim.Optimizer) – An optimizer object containing parameters for the learning rate scheduler

Returns

An object of torch.optim.lr_scheduler

Return type

torch.optim.lr_scheduler

colossalai.builder.builder.build_schedule(config)

Returns a schedule of colossalai.engine.schedule.BaseSchedule.

Parameters

config (dict or colossalai.context.Config) – A python dict or a colossalai.context.Config object containing information used in the construction of the return object

Returns

An object of colossalai.engine.schedule.BaseSchedule

Return type

colossalai.engine.schedule.BaseSchedule