Skip to content

[models] - feat(LayerSkip): implement LayerSkip model - #86

Merged
JulesBelveze merged 11 commits into
mainfrom
feat/models/layer-skip
Jul 28, 2026
Merged

[models] - feat(LayerSkip): implement LayerSkip model#86
JulesBelveze merged 11 commits into
mainfrom
feat/models/layer-skip

Conversation

@JulesBelveze

@JulesBelveze JulesBelveze commented Jan 31, 2026

Copy link
Copy Markdown
Owner

This PR adds LayerSkip support for BERT sequence classification!

Here are the additions:

  • Implements the paper's per-layer dropout and early-exit loss schedules.
  • Adds rotational, gradual, and all-layer curricula, plus fixed-depth inference.
  • Keeps fully dropped layers connected to autograd for distributed training.
  • Wires the model and callback into the training assistant.
  • Preserves Hugging Face serialization and head pruning.
  • Covers dropout, early exits, curriculum updates, training, and checkpoint reloads.

Note: the current implementation is limited to BERT models

…stic layer dropout for transformer layers

 - Introduce LayerDropoutWrapper class to selectively skip transformer layers during training based on a dropout probability
 - Forward pass conditionally bypasses layer execution to simulate layer dropout, retaining initial hidden states when skipped
…um callback for dynamic layer training

 - Introduce LayerSkipCurriculumCallback controlling layer contributions in BERT-based models
 - Support rotational and gradual curriculum types to adjust layer training dynamically
 - Allow for fixed training of the last layer through a configurable option
…out and early exit

 - Adds LtLayerSkip, a new Lightning module for fine-tuning with layer dropout and early exit strategy
 - Supports dynamic dropout scheduling and loss scaling based on model depth for efficient training
 - Enables both training and inference modes, with the ability to specify an early exiting layer during inference
 - Includes methods for forward passes with all layers or an early exit, as well as customized prediction steps
…el enhancements

 - Add tests for dropout schedule ensuring first layer has zero and last matches p_max
 - Test forward pass covers all model layers by examining tuple output and shape
 - Validate computed loss scales are in ascending order and sum to approximately one
 - Verify rotational curriculum functioning with LayerSkipCurriculumCallback in a module
 - Check early exit inference mode to ensure correct tensor output with specified exit layer
 - Add configuration mapping for LayerSkip training setup
 - Include LtLayerSkip model to the available models for training and usage
 - Integrate LayerDropoutWrapper to the custom transformers module
 - Implement LayerSkipCurriculumCallback for dynamic training adjustments
@JulesBelveze
JulesBelveze marked this pull request as draft January 31, 2026 11:18
JulesBelveze and others added 6 commits February 1, 2026 13:11
…n Seq2SeqTransformerDataModule

 - Implement caching for tokenizer creation to avoid redundant loads in `_get_seq2seq_tokenizer` function
 - Add support for optional source and target prefixes to be applied during tokenization

[bert_squeeze/models] - refactor: streamline LayerDropoutWrapper execution path

 - Simplify conditional layer execution in `LayerDropoutWrapper` for clearer logic
 - Centralize input preparation and hidden state retrieval in LtLayerSkip for evaluation steps
 - Extract repeated evaluation logic into a dedicated `_eval_step` method within LtLayerSkip
…for LayerSkip model

 - Introduce `train_layerskip.yaml` with configurations for training LayerSkip model in bert_squeeze
 - Include callback for curriculum learning with rotational period and optional training of the last layer
 - Define layer-specific learning rates and layer decay for discriminative learning approach
 - Set up model with parameters like exit layer, dropout schedule, and pretrained BERT model
 - Configure data module for processing with tokenizer and max sequence length settings
# Conflicts:
#	bert_squeeze/data/modules/transformer_module.py
…Skip

 - Enhanced the LayerDropoutWrapper to handle stochastic layer dropout more effectively, ensuring better management of hidden states and outputs during training.
 - Updated the LtLayerSkip class to enforce stricter validation on parameters and improved the handling of early exit logic, making the model more robust and user-friendly.
 - Enhance the LayerDropoutWrapper to better manage wrapped layers and their parameters, improving encapsulation and synchronization.
 - Update LtLayerSkip to support input embeddings directly, allowing for more flexible input handling during inference.
 - Enhanced the LayerDropoutWrapper to ensure proper type checking and state synchronization for the wrapped layer.
 - Simplified the forward pass logic and improved error handling for layer outputs, ensuring compatibility with transformer layers.
@JulesBelveze
JulesBelveze marked this pull request as ready for review July 28, 2026 14:53
@JulesBelveze
JulesBelveze merged commit 958bc42 into main Jul 28, 2026
9 checks passed
@JulesBelveze
JulesBelveze deleted the feat/models/layer-skip branch July 28, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant