Skip to content

Train all requested layerwise reranker heads - #1630

Open
Afloat16 wants to merge 1 commit into
FlagOpen:masterfrom
Afloat16:fix/layerwise-training-heads-20261112
Open

Afloat16 wants to merge 1 commit into
FlagOpen:masterfrom
Afloat16:fix/layerwise-training-heads-20261112

Conversation

@Afloat16

Copy link
Copy Markdown

Problem

The layerwise training wrapper records start_layer but does not pass cutoff_layers to its backbone. The backbone defaults to returning only the final layer. As a result, intermediate layer scores never reach the training loss: their supervised loss is missing, the self-distillation loop has no student layers, and independent intermediate classifier heads receive no gradients.

Changes

Pass the complete requested range, from start_layer through num_hidden_layers, when the training wrapper encodes pairs. The existing loss already supports multiple layer outputs, so no loss formula or backbone default needs to change. This also restores the layer selection used by the repository's earlier research training implementation in the current package entry point.

Validation

  • A real, locally initialized three-layer LayerWiseMiniCPMForCausalLM exercises shared and independent heads, three starting layers, external teacher targets, and self-distillation.
  • Compare every returned score, the full loss, and parameter gradients with explicit backbone calls for the requested cutoff layers; check that each requested independent head receives nonzero gradients.
  • Evaluation returns the requested layer scores with no training loss. Direct backbone calls still default to the final layer.
  • The 20 new cases produce 12 failures and 8 passes on the unchanged upstream base and 20 passes with this patch.
  • New cases plus existing Trainer/import compatibility modules: 28 passed, 1 skipped with PyTorch 2.15.0+cpu and Transformers 4.57.1. The skipped check requires Transformers 5.x. These tests require no checkpoint download; pretrained retrieval quality and CUDA execution were not evaluated.
  • Ruff on the new tests and git diff --check pass.

This branch has not been deployed

No deployments
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