-
Notifications
You must be signed in to change notification settings - Fork 28
Add CTRL contrib model port #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dhwanw
wants to merge
3
commits into
main
Choose a base branch
from
contrib/ctrl
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| # Contrib Model: CTRL | ||
|
|
||
| NeuronX Distributed Inference implementation of Salesforce CTRL. | ||
|
|
||
| ## Model Information | ||
|
|
||
| - **HuggingFace ID:** `Salesforce/ctrl` | ||
| - **Model Type:** Decoder-only transformer (conditional text generation) | ||
| - **Parameters:** 1.63B | ||
| - **Architecture:** 48 layers, 16 heads, hidden_size=1280, dff=8192 | ||
| - **Position Encoding:** Sinusoidal (computed, not learned) | ||
| - **Activation:** ReLU | ||
| - **License:** BSD-3-Clause | ||
|
|
||
| ## Architecture Details | ||
|
|
||
| CTRL uses control codes (e.g., `Links`, `Wikipedia`, `Science`) prepended to prompts to condition generation on a particular domain/style. Key differences from standard GPT-2: | ||
|
|
||
| - Sinusoidal position embeddings (not learned) | ||
| - Input embeddings scaled by sqrt(d_model) | ||
| - Separate lm_head with bias | ||
| - ReLU activation (not GELU) | ||
| - Pre-LayerNorm architecture | ||
|
|
||
| ## Validation Results | ||
|
|
||
| **Validated:** 2026-03-16 | ||
| **Configuration:** TP=1, batch_size=1, seq_len=128, bf16 | ||
|
|
||
| ### Test Results | ||
|
|
||
| | Test | Status | Result | | ||
| |------|--------|--------| | ||
| | Smoke Test | PASS | Model loads successfully | | ||
| | Token Matching (greedy) | PASS | **99.06% match** (634/640 tokens) | | ||
| | Token Matching (teacher-forced) | PASS | **99.84% match** | | ||
| | Profiling | PASS | **59.2 tokens/sec** | | ||
|
|
||
| **Status:** EXCELLENT | ||
|
|
||
| ## Usage | ||
|
|
||
| ```python | ||
| import torch | ||
| from neuronx_distributed_inference.models.config import NeuronConfig | ||
| from modeling_ctrl import NeuronCTRLForCausalLM, CTRLInferenceConfig | ||
|
|
||
| model_path = "/path/to/ctrl/" | ||
| compiled_model_path = "/path/to/compiled/" | ||
|
|
||
| # Configure | ||
| neuron_config = NeuronConfig( | ||
| tp_degree=1, | ||
| batch_size=1, | ||
| seq_len=128, | ||
| torch_dtype=torch.bfloat16, | ||
| ) | ||
|
|
||
| config = CTRLInferenceConfig.from_pretrained( | ||
| model_path, neuron_config=neuron_config, | ||
| ) | ||
|
|
||
| # Compile and load | ||
| model = NeuronCTRLForCausalLM(model_path, config) | ||
| model.compile(compiled_model_path) | ||
| model.load(compiled_model_path) | ||
|
|
||
| # Generate with control code | ||
| from transformers import AutoTokenizer | ||
| tokenizer = AutoTokenizer.from_pretrained(model_path) | ||
| inputs = tokenizer("Wikipedia The theory of relativity", return_tensors="pt") | ||
| # ... (see integration test for full example) | ||
| ``` | ||
|
|
||
| ## Compatibility Matrix | ||
|
|
||
| | Instance/Version | 2.20+ | 2.19 and earlier | | ||
| |------------------|-------|------------------| | ||
| | Trn1 | PASS (99.84% TF) | Not tested | | ||
| | Inf2 | Not tested | Not tested | | ||
|
|
||
| ## Performance | ||
|
|
||
| Profiled on trn1.32xlarge (single NeuronCore utilization): | ||
|
|
||
| | Metric | Context Encoding | Token Generation | | ||
| |--------|-----------------|------------------| | ||
| | Throughput | - | 59.3 tok/s | | ||
| | MBU (Memory) | 16.7% | 15.0% | | ||
| | MFU (Compute) | 7.6% | 0.1% | | ||
|
|
||
| *Batch size 1, sequence length 128, BF16 precision, TP=1* | ||
|
|
||
| ## Testing | ||
|
|
||
| Run integration tests: | ||
|
|
||
| ```bash | ||
| pytest contrib/models/ctrl/test/integration/test_model.py --capture=tee-sys | ||
| ``` | ||
|
|
||
| Or run manually: | ||
|
|
||
| ```bash | ||
| cd contrib/models/ctrl | ||
| python3 test/integration/test_model.py | ||
| ``` | ||
|
|
||
| ## Example Checkpoints | ||
|
|
||
| * Salesforce/ctrl | ||
|
|
||
| ## Maintainer | ||
|
|
||
| Neuroboros Team - Annapurna Labs | ||
|
|
||
| **Last Updated:** 2026-03-16 | ||
| **Validation Job:** SLURM 9589 | ||
Empty file.
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to "Annapurna Labs"