Skip to main content

meta-llama-3-yarn

Getting Started

Install with pip

pip install meta-llama-3-yarn

Build from source

You can also build and install meta-llama-3-yarn from source:

git clone https://github.com/MeetKai/meta-llama-3-yarn.git
cd meta-llama-3-yarn
pip install -e .

Usage

To use a Llama-3 model regardless whether it is a YaRN-scaled model:

import torch
from transformers import AutoTokenizer
from meta_llama_3_yarn import LlamaForCausalLM

model_name = "meta-llama/Meta-Llama-3-8B-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = LlamaForCausalLM.from_pretrained(
    model_name, device_map="auto", torch_dtype=torch.bfloat16
)

messages = [
    {"role": "user", "content": "Write a piece of quicksort code in C++"}
]
input_tensor = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt")
outputs = model.generate(input_tensor.to(model.device), max_new_tokens=100)

result = tokenizer.decode(outputs[0][input_tensor.shape[1]:], skip_special_tokens=True)
print(result)

To specifically scale a model using YaRN:

import torch
from transformers import AutoTokenizer
from meta_llama_3_yarn import LlamaForCausalLM, LlamaConfig

model_name = "meta-llama/Meta-Llama-3-8B-Instruct"
context_length = 32768
tokenizer = AutoTokenizer.from_pretrained(model_name)
config = LlamaConfig.from_pretrained(model_name)
config.rope_scaling = {"type": "yarn", "factor": context_length / config.max_position_embeddings}
model = LlamaForCausalLM.from_pretrained(
    model_name, config=config, device_map="auto", torch_dtype=torch.bfloat16
)

messages = [
    {"role": "user", "content": "Write a piece of quicksort code in C++"}
]
input_tensor = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt")
outputs = model.generate(input_tensor.to(model.device), max_new_tokens=100)

result = tokenizer.decode(outputs[0][input_tensor.shape[1]:], skip_special_tokens=True)
print(result)

Metadata

Release files for meta-llama-3-yarn 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for meta-llama-3-yarn 0.1.3
File Size Uploaded
meta_llama_3_yarn-0.1.3.tar.gz 23.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for meta-llama-3-yarn 0.1.3
File Interpreter ABI Platform
meta_llama_3_yarn-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 48.3 kB

Release files / meta_llama_3_yarn-0.1.3.tar.gz

Download URL meta_llama_3_yarn-0.1.3.tar.gz
Size 23.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ce67e915aef2fbda3da3d1e13774a7a69c1eb8b679a2b059bcf5369682a2c665
BLAKE2b-256 checksum
How to use checksums
147030bd2f256cc5bb209d24faf3f1f161d546e211c0042dcf8e6ba979585c43
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / meta_llama_3_yarn-0.1.3-py3-none-any.whl

Download URL meta_llama_3_yarn-0.1.3-py3-none-any.whl
Size 24.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ed4df3993c2cbce05f805e3be7a8af75087a1dd38c81e1ac0cfe0a41a1f57e5e
BLAKE2b-256 checksum
How to use checksums
b7da512872590065ce30a2a519ce7785742d77546cbc7c837ebdb66fca45448f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

1 release file

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page