Repository navigation
[RFC] Add configurable decoder layer execution (reference implementation) - #49489
Draft
bebetterest wants to merge 1 commit into
Draft
bebetterest wants to merge 1 commit into
bebetterest wants to merge 1 commit into
Conversation
Reuse original decoder parameters through configurable execution plans, with independent logical caches and model-specific state adapters. Include generation, distributed execution, Trainer integration, tests, and API documentation for upstream discussion. Co-Authored-By: GPT 6.1 <codex@openai.com>
Contributor
|
Thank you for your contribution 🤗! CI Security Gate — automatic approval blockedThis PR was not automatically approved for CI because the security gate failed. Possible reasons:
See the workflow run for the exact violations. A maintainer can review and manually approve CI if a finding is a false positive. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Discussion: #49488
This draft exposes a reference implementation of configurable decoder layer execution from transformers_loop. It lets a supported model load its original checkpoint, execute layers according to a configurable plan, share the original parameters across repeated visits, and retain independent cache/state histories for each logical execution.
The immediate purpose is technical discussion and an inspectable implementation for researchers. I am not requesting that the full extension be merged in its current form. The design can remain external, become loop-specific model definitions, or provide a starting point for smaller interfaces agreed with maintainers.
AI assistance disclosure: Implementation, tests, documentation, and these submission drafts were developed with substantial code-agent assistance. The current first-time contributor restriction applies; this draft does not claim to satisfy the PR template's assertion that the code and description were not written by an LLM or code agent.
Execution model
For a four-layer decoder,
[0, 1, 1, 2, 3]repeats only the second layer.[0, 1, 2, 3, 0, 1, 2, 3]repeats the complete stack as a block.Each call replaces the plan. Indices are zero-based, ranges are half-open, and the pass count includes the first visit. Plans must change between complete training steps; existing caches must be discarded after a change.
Changes included
layer_execution/This reference diff contains 42 files, with 7,114 added and 64 removed lines, against upstream
536ecc007387a50e77603bb5d92100e9b07514cc. Fork branding, the root loop guide, and the fork-maintenance document are excluded from the proposed diff. Their public links remain available as supplementary usage and validation records.The execution protocol targets causal decoder-only stacks whose prepared state streams preserve their shapes and structure across layers. Other models need an architecture adapter; a matching hidden width alone does not establish support. GPT-2, OPT, and Mamba are extension examples/tests, not automatically registered built-ins.
Recorded validation
The source/test contents are taken from fork commit
cf2d29f84c9b9449ac639a687737b9d957bc9fc2, synchronized with upstream536ecc007387a50e77603bb5d92100e9b07514cc. The following are previously recorded results for those contents, not claims about this PR's CI.The GPU environment used unmodified TRL 1.15.0, PEFT 0.21.2, Accelerate 1.15.0, DeepSpeed 0.19.7, and bitsandbytes 0.50.2. The selected matrix includes DDP, ZeRO-2/3, full-parameter training, LoRA, QLoRA, and original
Qwen/Qwen3.5-9Bweights at revisionc202236235762e1c871ad0ccb60c8ee5ba337b9a. Original full-parameter 9B checks use SGD; tiny and adapter runs use AdamW.The pinned maintenance record provides the selected matrix, dependency versions, skips, resolved bootstrap/environment failures, and interrupted attempts excluded from passing counts. Earlier full matrices belong to a separate fixed baseline and are not counted as reruns after synchronization.
Relevant local commands are:
PYTHONPATH=src HF_HUB_OFFLINE=1 python -m pytest tests/test_layer_execution*.py -q make check-repo make styleGPU and optional-backend cases require the corresponding hardware and dependencies. The recorded GPU results apply only while the submission branch's source/test contents match the pinned implementation. Submission-branch checks are recorded separately:
Checks run on the submission contents on 2026-10-11 (commit
db1a3aeb03551d5e84422f1851947648c6b93c88):src/andtests/match the pinned fork contents, and that the committed 42-file diff matches the reviewed patch.9fb191250dd56d0ba7ec9785a025ed29c03d5998. No runtime source change was needed.make check-reposucceeded. A separate--no-cacherun completed all 26 checker statuses successfully; the reviewer-assignment check skipped its work because the optional shared resolver is not installed.make stylecompleted all 5 checks successfully and left the committed diff unchanged.utils/tests_fetcher.py --diff_with_last_commit. Its reverse-dependency discovery failed on attention constants interpreted as module paths undercache_allocators/. The same class of failure was reproduced on unchanged upstream536ecc007387a50e77603bb5d92100e9b07514cc; no affected-test list or full-suite passing result is claimed.tests/test_layer_execution_multinode.py:112forsubprocess.Popen. This test uses asys.executableargument list, without a shell, to start two localtorchrunlaunchers for same-host simulation. The gate run and bot comment show that manual maintainer review/approval is required; full upstream CI has not been automatically approved. The test source is retained for review.Boundaries and design tradeoffs
model_impl="transformers"and TRL server/colocate modes. GRPO uses Hugging Face generation withuse_vllm=False.Related interfaces include KV sharing and heterogeneous layer configuration. The linked issue asks whether this should remain external, use distinct model definitions, or be reduced to a smaller core interface. Maintainer approval for such an upstream design has not yet been obtained.