Package: slapo
Slapo: A Schedule Language for Large Model TrainingDocumentationSlapo is a schedule language for progressive optimization of large deep learning model training.Large deep learning models demonstrate dominating model accuracy on a range of tasks in NLP and CV, but it is hard to train the model efficiently while preserving the usability. Slapo aims to address this tension through separation of concerns. Slapo decouples model execution from definition, enabling developers to use a set of schedule primitives to convert a PyTorch model for common model training optimizations without directly changing the model itself.Slapo highlights the following features::rocket:Progressive optimization. Slapo incorporates a "trace by need" approach that only traces a desired module to be a static graph for compiler-based aggressive optimizations.:building_construction:Structure-preserving scheduling. Slapo preserves the module hierarchy when constructing the schedule, so developers can easily locate the module and apply scheduling, which also facilitates the users to debug any performance and convergence issue.:gear:Auto-tuning. Slapo provides a programming interface that allows developers to specify a set of tuneable knobs to form an efficient tuning space, which can then be explored by Slapo auto-tuner to realize the optimal configuration.Getting StartedInstallationThere are two approaches to install Slapo:Install from PYPIpip3installslapoInstall from sourcegitclonehttps://github.com/awslabs/slapo.gitslapocdslapo
pip3install-e".[dev]"In addition, you can optionally installHuggingFace Transformers(>= v4.25.1) to retrieve models.
Also, Slapo currently supports the following frameworks, so you can run the scheduled models on these frameworks if needed.Megatron-LM>= 3.0.2DeepSpeed>= 0.7.7UsagePlease see theexamplesfolder for more details. Documentations will be released soon.importslapo# Load a PyTorch model from HuggingFace Hub, TorchVision, etc.fromtransformersimportBertLMHeadModel,AutoConfigconfig=AutoConfig.from_pretrained("bert-large-uncased")bert=BertLMHeadModel(config)# Create a default schedulesch=slapo.create_schedule(bert)# Apply primitives to optimize the model# Please refer to examples/bert/schedule.py for detailssch["bert.encoder.layer.0"].primitve(...)# Build an optimized modelopt_model=slapo.build(sch)# Run the optimized modelinputs=...outputs=opt_model(inputs)Supported PrimitivesTo maximally reduce the risk introduced by tracers and compilers, we leverageprogressive optimizationto gradually apply primitives to a part of the model. We classify the primitives into two categories. The first type of primitives doesnotrequire tracing and can be directly applied to modules and parameters; the second type of primitives requires a static graph, and thus needs to apply the.trace()primitive first.We provide the following primitives for dynamic graph optimizations:FeaturePrimitiveModule replacements[op].replace(new_module)Tensor parallelisms[op].shard(param_name, axis)Synchronizations[op].sync(mode="fwd_pre/fwd_post/bwd_post", sync_op_or_fn, **kwargs)Checkpointings[op].checkpoint()Fork random number generators[op].fork_rng()Annotate parameterss[op].annotate(param_name, key, value)And the following primitives for static graph optimizations:FeaturePrimitiveModule Tracings.trace(leaves, flatten)Pattern matchings.find(regex_or_pattern_fn)Operator fusions[op].fuse(compiler, subgraph)Layer decompositions[op].decompose()Partial module replacements[op].replace(new_module, subgraph)Partial gradient checkpointings[op].checkpoint(subgraph)Pipeline parallelisms[op].cut_pipeline_stage()You can look for all supported primitvies with the following API:importslapoprint(slapo.list_primitives())You could also check the description of each primitive on the fly:importslapohelp(slapo.list_primitives(name_only=False)["shard"])Auto-TuningWe also provide a light-weight interface for auto-tuning, so the developers can (1) construct a polyhedral search space using our APIs, and (2) leverage Slapo auto-tuner to automatically search for the best training configuration.cdbenchmark# Single device# The following script will trigger the tuning jobs for all the modelspython3tune_single_device.py# Single nodepython3tune_single_node.pyBenchmarkingWe provide scripts to reproduce our results on a single AWS EC2 p3.16xlarge node with 8 * V100 GPUs.cdbenchmark# Download datasetsbashdownload_benchmark_dataset.sh# Run benchmarking# Megatron-LM and Deepspeed are required for executing the experimentsbashrun_all_single_node.shconfig/single_node_v100.cfgPublicationIf you use Slapo in your project, please consult authors for citation.LicenseSlapo is released under theApache 2.0 license.