Na0s/sft-ready-Text-Generation-Augmented-Data
Viewer • Updated • 7.67M • 38 • 1
How to use Na0s/Mixtral-8x7B-Instruct-v0.1-exhaustive-LoRA with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="Na0s/Mixtral-8x7B-Instruct-v0.1-exhaustive-LoRA")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("Na0s/Mixtral-8x7B-Instruct-v0.1-exhaustive-LoRA")
model = AutoModelForCausalLM.from_pretrained("Na0s/Mixtral-8x7B-Instruct-v0.1-exhaustive-LoRA", device_map="auto")
messages = [
{"role": "user", "content": "Who are you?"},
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use Na0s/Mixtral-8x7B-Instruct-v0.1-exhaustive-LoRA with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "Na0s/Mixtral-8x7B-Instruct-v0.1-exhaustive-LoRA"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "Na0s/Mixtral-8x7B-Instruct-v0.1-exhaustive-LoRA",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/Na0s/Mixtral-8x7B-Instruct-v0.1-exhaustive-LoRA
How to use Na0s/Mixtral-8x7B-Instruct-v0.1-exhaustive-LoRA with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "Na0s/Mixtral-8x7B-Instruct-v0.1-exhaustive-LoRA" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "Na0s/Mixtral-8x7B-Instruct-v0.1-exhaustive-LoRA",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'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 "Na0s/Mixtral-8x7B-Instruct-v0.1-exhaustive-LoRA" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "Na0s/Mixtral-8x7B-Instruct-v0.1-exhaustive-LoRA",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use Na0s/Mixtral-8x7B-Instruct-v0.1-exhaustive-LoRA with Docker Model Runner:
docker model run hf.co/Na0s/Mixtral-8x7B-Instruct-v0.1-exhaustive-LoRA
LoRA fine-tuned version of mistralai/Mixtral-8x7B-Instruct-v0.1 targeting all the modules.
quantization_config = transformers.BitsAndBytesConfig(load_in_4bit=True)
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mixtral-8x7B-Instruct-v0.1", truncation=True, padding=True, padding_side="right")
model = AutoModelForCausalLM.from_pretrained("mistralai/Mixtral-8x7B-Instruct-v0.1", quantization_config=quantization_config)
tokenizer.add_special_tokens({'pad_token': '[PAD]'})
model = prepare_model_for_kbit_training(model)
config = LoraConfig(r = 4,
lora_alpha=4,
target_modules = ["gate", "q_proj", "k_proj", "v_proj", "o_proj",
"gate_proj", "up_proj", "down_proj"],
lora_dropout=0.1
)
lora_model = get_peft_model(model, config)
lora_model.print_trainable_parameters()
dataset = load_dataset("Na0s/sft-ready-Text-Generation-Augmented-Data", split="train")
trainer = SFTTrainer(
model = lora_model,
tokenizer = tokenizer,
train_dataset = dataset,
packing = True,
args = TrainingArguments(
per_device_train_batch_size = 1,
gradient_accumulation_steps = 16,
group_by_length = True,
warmup_steps = 5,
bf16 = True,
max_steps=10000,
learning_rate = 2e-4,
optim = "adamw_8bit",
weight_decay = 0.01,
lr_scheduler_type = "cosine",
seed = 3407,
eval_strategy="no",
do_eval=False,
output_dir = "./outputs",
push_to_hub=True,
remove_unused_columns=False,
)
)
torch.cuda.empty_cache()
trainer.train()
Upcoming.
Carbon emissions can be estimated using the Machine Learning Impact calculator presented in Lacoste et al. (2019).
The objective of the fine-tuning of this MoE based transformer is to implement the expert pruning detailed in the following paper: A Provably Effective Method for Pruning Experts in Fine-tuned Sparse Mixture-of-Experts