Text Generation
Transformers
PyTorch
Safetensors
mistral
finetuned
mistral-common
conversational
text-generation-inference
Instructions to use Bepemin/Babelbit-h1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Bepemin/Babelbit-h1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Bepemin/Babelbit-h1") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Bepemin/Babelbit-h1") model = AutoModelForCausalLM.from_pretrained("Bepemin/Babelbit-h1", 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]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Bepemin/Babelbit-h1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Install mistral-common: pip install --upgrade mistral-common # Start the vLLM server: vllm serve "Bepemin/Babelbit-h1" --tokenizer_mode mistral --config_format mistral --load_format mistral --tool-call-parser mistral --enable-auto-tool-choice # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Bepemin/Babelbit-h1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Bepemin/Babelbit-h1
- SGLang
How to use Bepemin/Babelbit-h1 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 "Bepemin/Babelbit-h1" \ --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": "Bepemin/Babelbit-h1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "Bepemin/Babelbit-h1" \ --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": "Bepemin/Babelbit-h1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Bepemin/Babelbit-h1 with Docker Model Runner:
docker model run hf.co/Bepemin/Babelbit-h1
nghiatrannnnnn commited on
scorevision: push artifact
Browse files- download_model.py +75 -0
download_model.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from huggingface_hub import snapshot_download
|
| 2 |
+
import os
|
| 3 |
+
import torch
|
| 4 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 5 |
+
|
| 6 |
+
def download_model():
|
| 7 |
+
"""
|
| 8 |
+
Tải mô hình Mistral-7B-Instruct từ Hugging Face Hub.
|
| 9 |
+
Trả về đường dẫn đến thư mục chứa mô hình đã tải.
|
| 10 |
+
"""
|
| 11 |
+
print("Bắt đầu tải mô hình Mistral-7B-Instruct...")
|
| 12 |
+
|
| 13 |
+
# Đặt biến môi trường HUGGING_FACE_HUB_TOKEN nếu bạn có token
|
| 14 |
+
hf_token = os.getenv("HUGGINGFACE_API_KEY")
|
| 15 |
+
|
| 16 |
+
# Tải mô hình từ Hugging Face Hub
|
| 17 |
+
model_path = snapshot_download(
|
| 18 |
+
repo_id="mistralai/Mistral-7B-Instruct-v0.2",
|
| 19 |
+
token=hf_token,
|
| 20 |
+
revision="main"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
print(f"Đã tải mô hình từ Hugging Face Hub vào: {model_path}")
|
| 24 |
+
|
| 25 |
+
# Kiểm tra mô hình đã tải
|
| 26 |
+
try:
|
| 27 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 28 |
+
print("✅ Tokenizer đã tải thành công!")
|
| 29 |
+
|
| 30 |
+
# Kiểm tra xem có GPU không để quyết định precision
|
| 31 |
+
if torch.cuda.is_available():
|
| 32 |
+
print("Phát hiện GPU, sẽ sử dụng half precision...")
|
| 33 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 34 |
+
model_path,
|
| 35 |
+
torch_dtype=torch.float16,
|
| 36 |
+
device_map="auto"
|
| 37 |
+
)
|
| 38 |
+
else:
|
| 39 |
+
print("Không phát hiện GPU, sử dụng CPU...")
|
| 40 |
+
model = AutoModelForCausalLM.from_pretrained(model_path)
|
| 41 |
+
|
| 42 |
+
print("✅ Model đã tải thành công!")
|
| 43 |
+
|
| 44 |
+
# Kiểm tra pad token
|
| 45 |
+
if tokenizer.pad_token is None:
|
| 46 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 47 |
+
print("Đã thiết lập pad_token = eos_token")
|
| 48 |
+
|
| 49 |
+
# Thử nghiệm mô hình với một câu đơn giản
|
| 50 |
+
test_text = "Xin chào, tôi là"
|
| 51 |
+
print(f"Thử nghiệm với input: '{test_text}'")
|
| 52 |
+
|
| 53 |
+
inputs = tokenizer(test_text, return_tensors="pt")
|
| 54 |
+
if torch.cuda.is_available():
|
| 55 |
+
inputs = inputs.to("cuda")
|
| 56 |
+
|
| 57 |
+
with torch.no_grad():
|
| 58 |
+
outputs = model.generate(
|
| 59 |
+
**inputs,
|
| 60 |
+
max_new_tokens=20,
|
| 61 |
+
do_sample=True,
|
| 62 |
+
temperature=0.7,
|
| 63 |
+
top_p=0.95
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 67 |
+
print(f"Kết quả: '{generated_text}'")
|
| 68 |
+
|
| 69 |
+
except Exception as e:
|
| 70 |
+
print(f"Lỗi khi kiểm tra mô hình: {e}")
|
| 71 |
+
|
| 72 |
+
return model_path
|
| 73 |
+
|
| 74 |
+
if __name__ == "__main__":
|
| 75 |
+
download_model()
|