Instructions to use shumi2011/ivote3p with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use shumi2011/ivote3p with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="shumi2011/ivote3p")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("shumi2011/ivote3p", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use shumi2011/ivote3p with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "shumi2011/ivote3p" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shumi2011/ivote3p", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/shumi2011/ivote3p
- SGLang
How to use shumi2011/ivote3p 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 "shumi2011/ivote3p" \ --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": "shumi2011/ivote3p", "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 "shumi2011/ivote3p" \ --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": "shumi2011/ivote3p", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use shumi2011/ivote3p with Docker Model Runner:
docker model run hf.co/shumi2011/ivote3p
Mô hình iVote3P - Tiếng Việt
==============================================================
_ _ __ _ _____
(_) | / /___ | |_ ___ |___ /
| | | / / _ \ | __/ _ \ |_ | | | / / (_) || |_ __/ ___) |
|_|_|/_/ \___/ \__\___| |____/ ver:1.0 18/8/2026
==============================================================
Đây là một mô hình ngôn ngữ iVote3P phiên bản 1.0
Chi tiết Mô hình
Mô hình iVote3P được phát triển dựa trên kiến trúc iVoteModel tùy chỉnh.
Các tham số chính của mô hình được cấu hình như sau (chi tiết đầy đủ có trong config.json):
- Kiến trúc:
iVoteModel(GPT-like, custom) - Kích thước Từ vựng (Vocab Size): 50368
- Độ dài Ngữ cảnh (Context Length): 2048
- Số lớp (Number of Layers): 18
- Kích thước Nhúng (Embedding Dimension): 640
- Kích thước Hidden (Hidden Dimension): 2048
- Số đầu Attention (Number of Heads): 10
- Kích thước Head (Head Dimension): 64
- Số nhóm KV (KV Groups): 2
- Chuẩn hóa QK (QK Norm): True (Mode: 2)
- Định dạng Trọng số:
safetensors
Cách sử dụng
Để sử dụng mô hình này, bạn cần tải toàn bộ file từ repo về, chúng tôi có sẵn ipynb để bạn sử dụng.
Cài đặt và Tải Toàn Bộ File
Cài đặt thư viện:
pip install torch safetensors huggingface_hub tokenizersTải toàn bộ repo về máy: Bạn có thể dùng
huggingface_hubđể tải toàn bộ thư mục mô hình về máy (ví dụ tải vào thư mục./ivote3p_model):from huggingface_hub import snapshot_download model_dir = snapshot_download(repo_id="shumi2011/ivote3p", local_dir="./ivote3p_model") print(f"Đã tải toàn bộ file mô hình về: {model_dir}")Đảm bảo codebase
iVote3Pcó sẵn: Sao chép thư mụcivote3p/từ dự ániVote3Pgốc vào thư mục làm việc của bạn hoặc thêm đường dẫn đến nó vàosys.path.
Tải mô hình và Inference (Tạo văn bản)
Sau khi đã tải repo về máy, bạn có thể khởi tạo mô hình và inference như sau:
import sys
import json
from pathlib import Path
import torch
import safetensors.torch
from tokenizers import Tokenizer
# Khai báo đường dẫn đến thư mục vừa tải
MODEL_DIR = Path("./ivote3p_model")
# Đảm bảo hàm generate_text và iVoteModel được import từ codebase gốc
# sys.path.append("/path/to/your/iVote3P_project")
from ivote3p.parity_model import iVoteModel, generate_text
# --- Bước 1: Tải Tokenizer ---
tokenizer = Tokenizer.from_file(str(MODEL_DIR / "tokenizer.json"))
# --- Bước 2: Tải cấu hình mô hình (config.json) ---
with open(MODEL_DIR / "config.json", 'r', encoding='utf-8') as f:
model_cfg_params = json.load(f)
# --- Bước 3: Khởi tạo mô hình tùy chỉnh `iVoteModel` ---
model_cfg_for_init = {k: v for k, v in model_cfg_params.items() if k not in ['_name_or_path', 'architectures', 'torch_dtype', 'transformers_version', 'model_type']}
if isinstance(model_cfg_for_init.get('dtype'), str):
model_cfg_for_init['dtype'] = getattr(torch, model_cfg_for_init['dtype'].rsplit('.', 1)[-1])
model = iVoteModel(model_cfg_for_init)
# --- Bước 4: Tải trọng số mô hình (model.safetensors) ---
state_dict = safetensors.torch.load_file(MODEL_DIR / "model.safetensors", device="cpu")
model.load_state_dict(state_dict, strict=False)
# Chuyển mô hình sang chế độ đánh giá và đẩy lên thiết bị (GPU nếu có)
model.eval()
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
print("Mô hình và tokenizer đã được tải và sẵn sàng sử dụng.")
# --- Bước 5: Chạy Inference ---
prompt = "[BOS]Xin chào, đây là một câu chuyện về"
with torch.no_grad():
generated_text_custom = generate_text(model, tokenizer, prompt, device, max_new_tokens=100)
print("
--- Văn bản tạo ra ---")
print(generated_text_custom)
Sample:
from huggingface_hub import snapshot_download
from tokenizers import Tokenizer
import safetensors.torch
import torch
import json
import sys
from pathlib import Path
# --- 1. Tải toàn bộ repo về thư mục cục bộ ---
repo_id = "shumi2011/ivote3p"
local_model_dir = Path("./ivote3p_model_local")
print(f"Đang tải mô hình từ repo_id về local_model_dir...")
snapshot_download(repo_id=repo_id, local_dir=local_model_dir)
print("Tải hoàn tất!")
# --- 2. Khởi tạo Tokenizer và Config ---
tokenizer = Tokenizer.from_file(str(local_model_dir / "tokenizer.json"))
with open(local_model_dir / "config.json", 'r', encoding='utf-8') as f:
model_cfg_params = json.load(f)
# --- 3. Khởi tạo Model (dùng hàm pm.iVoteModel đã có từ quá trình train) ---
model_cfg_for_init = {k: v for k, v in model_cfg_params.items() if k not in ['_name_or_path', 'architectures', 'torch_dtype', 'transformers_version', 'model_type']}
if isinstance(model_cfg_for_init.get('dtype'), str):
model_cfg_for_init['dtype'] = getattr(torch, model_cfg_for_init['dtype'].rsplit('.', 1)[-1])
local_model = pm.iVoteModel(model_cfg_for_init)
# --- 4. Tải trọng số từ file safetensors ---
state_dict = safetensors.torch.load_file(local_model_dir / "model.safetensors", device="cpu")
local_model.load_state_dict(state_dict, strict=False)
device = "cuda" if torch.cuda.is_available() else "cpu"
local_model.to(device)
print("Mô hình local đã sẵn sàng!")
# --- 5. Chạy thử Inference ---
local_model.eval()
prompt = "[BOS] Ngay"
with torch.no_grad():
text = pm.generate_text(local_model, tokenizer, prompt, device, max_new_tokens=40)
print(text)
Fine-tuning (Huấn luyện lại)
Để fine-tune hoặc tiếp tục huấn luyện mô hình iVote3P trên dữ liệu mới:
- Dữ liệu: Chuẩn bị dữ liệu và encode nó thành file
.binsử dụng filetokenizer.jsonbạn vừa tải về trong thư mục./ivote3p_model. - Khởi tạo Model: Làm tương tự Bước 1 đến Bước 4 ở phần Inference bên trên để có biến
model. - Vòng lặp huấn luyện: Sử dụng optimizer, tính toán loss và step cập nhật như trong project gốc
iVote3P.
# Ví dụ thiết lập optimizer từ codebase
# from ivote3p.parity_model import build_optimizer_param_groups, forward_with_mtp_loss
# optimizer = torch.optim.AdamW(
# build_optimizer_param_groups(model, model_cfg_params, weight_decay=0.0),
# lr=1e-5,
# betas=(0.9, 0.999),
# )
# model.train()
# # X, Y = get_batch("train")
# # fw = forward_with_mtp_loss(model, X, Y, model_cfg_params, iter + 1)
# # total_loss = fw["total_loss"]
# # optimizer.zero_grad()
# # total_loss.backward()
# # optimizer.step()
Dữ liệu Huấn luyện
Mô hình được huấn luyện trên một tập dữ liệu tiếng Việt tùy chỉnh, tập trung vào các đặc tính văn bản cụ thể liên quan đến dự án iVote3P.
Tokenizer
Tokenizer được sử dụng là một tokenizer Byte-Pair Encoding (BPE) tùy chỉnh, được huấn luyện trên dữ liệu tiếng Việt.
Lời cảm ơn
Mô hình này là một phần của dự án iVote3P.
- Downloads last month
- 211
