BTLM-3B-8k-base
Bittensor Language Model (BTLM-3B-8k-base) is a 3 billion parameter language model with an 8k context length trained on 627B tokens of SlimPajama. BTLM-3B-8k-base sets a new standard for 3B parameter models, outperforming models trained on hundreds of billions more tokens and achieving comparable performance to open 7B parameter models. BTLM-3B-8k-base can also be quantized to 4-bit to fit in devices with as little as 3GB of memory. The model is made available with an Apache 2.0 license for commercial use.
BTLM was trained by Cerebras in partnership with Opentensor on the newly unveiled Condor Galaxy 1 (CG-1) supercomputer, the first public deliverable of the G42-Cerebras strategic partnership.
BTLM-3B-8k was trained with a similar architecture to CerebrasGPT with the addition of SwiGLU nonlinearity, ALiBi position embeddings, and maximal update parameterization (muP). The model was trained for 1 epoch of SlimPajama-627B. 75% of training was performed with 2k sequence length. The final 25% of training was performed at 8k sequence length to enable long sequence applications
Read our paper for more details!
BTLM-3B-8k Highlights
BTLM-3B-8k-base:
- Licensed for commercial use (Apache 2.0).
- State of the art 3B parameter model.
- Provides 7B model performance in a 3B model via performance enhancements from ALiBi, SwiGLU, maximal update parameterization (muP) and the the extensively deduplicated and cleaned SlimPajama-627B dataset.
- Fits in devices with as little as 3GB of memory when quantized to 4-bit.
- One of few 3B models that supports 8k sequence length thanks to ALiBi.
- Requires 71% fewer training FLOPs, has 58% smaller memory footprint for inference than comparable 7B models.
Usage
Note: Transformers does not support muP for all models, so BTLM-3B-8k-base requires a custom model class. This causes a situation where users must either (1) enable trust_remote_code=True
when loading the model or (2) acknowledge the warning about code execution upon loading the model.
With generate():
from transformers import AutoTokenizer, AutoModelForCausalLM
# Load the tokenizer and model
tokenizer = AutoTokenizer.from_pretrained("cerebras/btlm-3b-8k-base")
model = AutoModelForCausalLM.from_pretrained("cerebras/btlm-3b-8k-base", trust_remote_code=True, torch_dtype="auto")
# Set the prompt for generating text
prompt = "Albert Einstein was known for "
# Tokenize the prompt and convert to PyTorch tensors
inputs = tokenizer(prompt, return_tensors="pt")
# Generate text using the model
outputs = model.generate(
**inputs,
num_beams=5,
max_new_tokens=50,
early_stopping=True,
no_repeat_ngram_size=2
)
# Convert the generated token IDs back to text
generated_text = tokenizer.batch_decode(outputs, skip_special_tokens=True)
# Print the generated text
print(generated_text[0])
With pipeline:
from transformers import AutoTokenizer, AutoModelForCausalLM
from transformers import pipeline
# Load the tokenizer and model
tokenizer = AutoTokenizer.from_pretrained("cerebras/btlm-3b-8k-base")
model = AutoModelForCausalLM.from_pretrained("cerebras/btlm-3b-8k-base", trust_remote_code=True, torch_dtype="auto")
# Set the prompt for text generation
prompt = """Isaac Newton was a """
# Create a text generation pipeline
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
# Generate text using the pipeline
generated_text = pipe(
prompt,
max_length=50,
do_sample=False,
no_repeat_ngram_size=2)[0]
# Print the generated text
print(generated_text['generated_text'])
Evaluations and Comparisons to Other Models
Memory Requirements
Figure 1. Memory requirements of different model sizes and quantization schemes
Quality, Training Cost, Memory Footprint, Inference Speed
Figure 2: Comparisons of quality, memory footprint & inference cost between BTLM-3B-8K and 7B model families.
Performance vs 3B models
Table 1: Performance at 3B model size. Detailed down-stream tasks comparisons. MMLU task performance is reported using 5-shot, other tasks are 0-shot.
Figure 3: Performance at 3B model size
Performance vs 7B models
Table 2: Performance at 7B model size. Detailed down-stream tasks comparisons. MMLU task performance is reported using 5-shot, everything else is 0-shot.
Figure 4: Performance at 7B model size
Long Sequence Lengths
To enable long sequence applications, we use ALiBi position embeddings and trained on 470B tokens at the context length of 2,048 followed by 157B of tokens trained at 8,192 context length. To assess BTLMβs long sequence capability, we evaluate it on SlimPajama test set with 32,768 context length and plot loss at each token position. Although ALiBi allows extrapolation in theory, 2,048 context length training alone does not extrapolate well in practice. Thankfully variable sequence length training allows for substantially improved extrapolation. BTLM-3B extrapolates well up to 10k context length but the performance degrades slightly beyond this.
Figure 5: BTLM-3B model's cross-entropy evaluation on the SlimPajamaβs test set. Inference performed on the extrapolated sequence length of 32,768 tokens.
Model Details
- Developed by: Cerebras Systems and Opentensor with generous support from G42 Cloud and IIAI
- License: Apache 2.0
- Model type: Decoder-only Language Model
- Architecture: GPT-2 style architecture with SwiGLU, ALiBi, and muP
- Data set: SlimPajama-627B
- Tokenizer: Byte Pair Encoding
- Vocabulary Size: 50257
- Sequence Length: 8192
- Optimizer: AdamW
- Positional Encoding: ALiBi
- Language: English
- Learn more: BTLM-3B-8k blog
- Paper: BTLM-3B-8K: 7B Parameter Performance in a 3B Parameter Model
To continue training with PyTorch and Maximal Update Parameterization
from transformers import AutoModelForCausalLM
import torch
model = AutoModelForCausalLM.from_pretrained("cerebras/btlm-3b-8k-base", trust_remote_code=True)
# Get the parameter groups for the muP optimizer
param_groups = model.get_mup_param_groups(lr=1e-3, weight_decay=0.1)
# Set up the optimizer using AdamW with muP parameters
optimizer = torch.optim.AdamW(
param_groups,
betas=(0.9, 0.95),
eps=1e-8
)
Ensure the following muP parameters are passed in your config, otherwise your model will default to standard parameterization
mup_width_scale: <float>
mup_embeddings_scale: <float>
mup_output_alpha: <float>
mup_scale_qk_dot_by_d: true
To extend the context length with Position Interpolation
During inference (without fine-tuning):
It's possible to extend the context length to 2x the training context length without degradation in performance using dynamic linear scaling. Dynamic linear scaling adjusts the slopes of ALiBi with a factor of input_seq_len/train_seq_len
when input_seq_len
is larger than train_seq_len
. Check the details in our paper Position Interpolation Improves ALiBi Extrapolation. To enable dynamic linear scaling, update config.json
as follows:
# update `n_positions` with the maximum context length will be
# encountered during inference (e.g. 16384 tokens)
"n_positions": 16384,
# specify `train_seq_len` in `alibi_scaling` parameter
"alibi_scaling": {
"type": "linear",
"train_seq_len": 8192
}
Using fine-tuning + position interpolation:
Performing fine-tuning with position interpolation can help achieve greater extrapolation lengths. The scaling factor should be fixed to finetuning_seq_len/train_seq_len
. To enable fixed linear scaling, update config.json
as follows:
# update `n_positions` with the fine-tuning context length (e.g. 32768 tokens)
"n_positions": 32768,
# specify the scaling `factor` in `alibi_scaling` parameter
"alibi_scaling": {
"type": "linear",
"factor": 4.0
}
Uses and Limitations
Intended Use
The primary intended use is to further research into large language models. BTLM-3B-8k-base can be used as a foundation model for NLP, applications, ethics, and alignment research. We release these models with a fully permissive Apache license for the community to use freely.
You may fine-tune and adapt BTLM-3B-8k-base model via either Cerebras Model Studio or third-party libraries. Further safety-related testing and mitigations should be applied before using the BTLM-3B-8k-base in production downstream applications.
Out of Scope Use
BTLM-3B-8k-base was trained on SlimPajama, with primarily English language, and is not recommended for machine translation tasks. BTLM-3B-8k-base has not been tuned for instruction-following or chat-based use cases.
Generation Samples
Prompt: What is a manometer?"
Generation: "A manometric device is an instrument that measures the pressure of a fluid."
Prompt: "What Robert Oppenheimer is famous for?"
Generation: βRobert Opperman was a physicist who was the director of the Manhattan Project, which was responsible for the development of nuclear weapons.β
Prompt: "What was Albert Einstein known for?"
Generation: βAlbert Einstein was a German-born theoretical physicist who developed the theory of relativity, one of the two pillars of modern physics (alongside quantum mechanics).β
Prompt: βWho is Isaac Newton?β
Generation: βIsaac Newton was an English physicist, mathematician, astronomer, alchemist, and theologian. He is widely recognized as one of the most influential scientists of all time and as a key figure in the scientific revolution.β
Prompt: "Where does the blood get pumped to after it leaves the right ventricle?"
Generation: βThe right atrium receives the deoxygenated blood from the pulmonary artery. The right side of the heart is the only side that receives de-oxygened...β
Prompt: "Peter lost his wallet after attending a local concert. To help him, Bob gave David 10 dollars. David then passed it on to Peter. Now what is the total amount of money Peter has?"
Generation: βA. $10β
Risk, Bias, Ethical Considerations
- Human life: The outputs from this model may or may not align with human values. The risk needs to be thoroughly investigated before deploying this model in a production environment where it can directly impact human life.
- Risks and harms: There may be distributional bias in the RedPajama dataset that can manifest in various forms in the downstream model deployment. There are other risks associated with large language models such as amplifying stereotypes, memorizing training data, or revealing private or secure information.
Acknowledgements
We are thankful to all Cerebras engineers that made this work possible.
We would like to acknowledge the generous support of G42 Cloud and the Inception Institute of Artificial Intelligence for providing compute time on Condor Galaxy 1.
- Downloads last month
- 470