Text Generation
Transformers
PyTorch
English
llama
llama2
100k
7b
custom_code
text-generation-inference
Instructions to use lyogavin/Anima-7B-100K with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use lyogavin/Anima-7B-100K with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="lyogavin/Anima-7B-100K", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("lyogavin/Anima-7B-100K", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("lyogavin/Anima-7B-100K", trust_remote_code=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use lyogavin/Anima-7B-100K with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "lyogavin/Anima-7B-100K" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lyogavin/Anima-7B-100K", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/lyogavin/Anima-7B-100K
- SGLang
How to use lyogavin/Anima-7B-100K with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "lyogavin/Anima-7B-100K" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lyogavin/Anima-7B-100K", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "lyogavin/Anima-7B-100K" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lyogavin/Anima-7B-100K", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use lyogavin/Anima-7B-100K with Docker Model Runner:
docker model run hf.co/lyogavin/Anima-7B-100K
Anima LLM supporting 100K input token length. It's trained based on Llama2 7B, so the license support commercial use!
We carefully curated long QA training dataset from 30k to 100k length to train this model. We also made a lot of memory optimizations to make it scale to 100k tokens.
How to train/infer?
install dependencies
# Please update the path of `CUDA_HOME`
export CUDA_HOME=/usr/local/cuda-11.8
pip install transformers==4.31.0
pip install sentencepiece
pip install ninja
pip install flash-attn --no-build-isolation
pip install git+https://github.com/HazyResearch/flash-attention.git#subdirectory=csrc/rotary
pip install git+https://github.com/HazyResearch/flash-attention.git#subdirectory=csrc/xentropy
pip install evaluate
pip install git+https://github.com/huggingface/peft.git@v0.4.0
pip install wandb
inference
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
base_model = "lyogavin/Anima-7B-100K"
tokenizer = AutoTokenizer.from_pretrained(base_model)
model = AutoModelForCausalLM.from_pretrained(
base_model,
torch_dtype=torch.float16,
trust_remote_code=True,
device_map="auto",
)
model.eval()
prompt = "Where is the capital of US?"
inputs = tokenizer(prompt, return_tensors="pt")
inputs['input_ids'] = inputs['input_ids'].cuda()
inputs['attention_mask'] = inputs['attention_mask'].cuda()
# Generate
generate_ids = model.generate(**inputs, max_new_tokens=30,
only_last_logit=True, # to save memory
use_cache=False, # when run into OOM, enable this can save memory
xentropy=True)
output = tokenizer.batch_decode(generate_ids,
skip_special_tokens=True,
clean_up_tokenization_spaces=False)[0]
Training
./run_longer_training.sh
Evaluations
There's almost none evaluation dataset designed for 100k tokens. So we designed/curated some dataset for this model. We compared this model and several other public/private models.
1. longchat topic retrieval
| Model | Accuracy |
|---|---|
| Claude2 | 0.9 |
| together llama2 32k | 0.15 |
| longchat 32k 1.5 | 0.05 |
| Anima 100K | 0.5 |
2. longchat number retrieval
| Model | Accuracy |
|---|---|
| Claude2 | 0.85 |
| together llama2 32k | 0.2 |
| longchat 32k 1.5 | 0.05 |
| Anima 100K | 0.45 |
3. Narrative QA in zeroscore
| Model | F1 |
|---|---|
| Claude2 | 0.6187 |
| together llama2 32k | 0.3833 |
| longchat 32k 1.5 | 0.2416 |
| Anima 100K | 0.4919 |
Github
Github repo is here
- Downloads last month
- 349