Text Generation
Transformers
PyTorch
Persian
English
ysnrfd
From_Scratch
Custom
YSNRFD
LLM
Persian_LLM
English_LLM
Instructions to use ysn-rfd/ysnrfd-base-V2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ysn-rfd/ysnrfd-base-V2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ysn-rfd/ysnrfd-base-V2")# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("ysn-rfd/ysnrfd-base-V2", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use ysn-rfd/ysnrfd-base-V2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ysn-rfd/ysnrfd-base-V2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ysn-rfd/ysnrfd-base-V2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/ysn-rfd/ysnrfd-base-V2
- SGLang
How to use ysn-rfd/ysnrfd-base-V2 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 "ysn-rfd/ysnrfd-base-V2" \ --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": "ysn-rfd/ysnrfd-base-V2", "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 "ysn-rfd/ysnrfd-base-V2" \ --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": "ysn-rfd/ysnrfd-base-V2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use ysn-rfd/ysnrfd-base-V2 with Docker Model Runner:
docker model run hf.co/ysn-rfd/ysnrfd-base-V2
REPORT ANY PROBLEMS IN MODEL LOADING AND INFERENCE
Model Details
WARNINNGS: This Model IS Pre-Trained, in the future will be finetuned.
- I changed the number of attention heads from 12 to 32.
- The hidden size remains unchanged.
- The tokenizer must be updated.
Model Description
The First Persian LLM By YSNRFD, This Model support Only English text Inputs, In The Future I Want Add Persian Language Support.
- Developed by: ysnrfd
- Funded by: ysnrfd
- Shared by: ysnrfd
- Model type: LLM
- Language(s) (NLP): English
- License: ysnrfd LICENSE
INFERENCE
The package below must be installed in this exact way. I'm sorry that I couldn’t upload it to PyPI.
# GITHUB REPO
PUBLIC_WHL_URL="https://github.com/ysnrfd/ysnrfd_architecture_whl/releases/download/WHL/ysnrfd-1.1.0-py3-none-any.whl"
# PACKAGE INSTALL
!pip install $PUBLIC_WHL_URL
CODE FOR START TEXT GENERATION
import torch
from transformers import AutoTokenizer, PreTrainedTokenizer
import logging
# Logging settings
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# ----------------------------------------------------
# 1. Importing architecture classes (from your locally installed package)
# ----------------------------------------------------
# This line loads Ysnrfd classes from your installed package (.whl), without needing the source code.
try:
from ysnrfd import YsnrfdConfig, YsnrfdForCausalLM
logger.info(" Ysnrfd classes were successfully loaded from the local package.")
except ImportError:
logger.error(" Import error: Make sure the 'ysnrfd' package (.whl file) is installed.")
# You may stop the program here
exit()
# ----------------------------------------------------
# 2. Setting the model identifier (Hugging Face Hub)
# ----------------------------------------------------
# This is the trained model identifier and its weights.
HF_MODEL_ID = "ysn-rfd/ysnrfd-base-V2"
# Device selection (GPU or CPU)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
logger.info(f"Using device: {device}")
# ----------------------------------------------------
# 3. Loading the tokenizer and configuration
# ----------------------------------------------------
try:
# Load tokenizer using AutoTokenizer standard
tokenizer: PreTrainedTokenizer = AutoTokenizer.from_pretrained(HF_MODEL_ID)
# Load config.json from the Hub and inject it into the custom YsnrfdConfig class
# This class comes from your package, but the values are read from the Hub's config.json.
config: YsnrfdConfig = YsnrfdConfig.from_pretrained(HF_MODEL_ID)
# Set pad_token_id if not defined (required for generation)
if tokenizer.pad_token_id is None:
tokenizer.pad_token_id = tokenizer.eos_token_id
logger.info(f" Configuration and tokenizer loaded successfully. Config type: {type(config)}")
except Exception as e:
logger.error(f" Error loading configuration/tokenizer from the Hub: {e}")
exit()
# ----------------------------------------------------
# 4. Loading the model and weights
# ----------------------------------------------------
try:
# Load model weights from the Hub into your custom architecture class
model: YsnrfdForCausalLM = YsnrfdForCausalLM.from_pretrained(HF_MODEL_ID, config=config)
model.to(device)
model.eval()
logger.info(" Model and weights loaded successfully and moved to device.")
except Exception as e:
logger.error(f" Error loading model from the Hub: {e}")
exit()
# ----------------------------------------------------
# 5. Running Inference (text generation)
# ----------------------------------------------------
prompt = "On a sunny day in Tehran,"
logger.info(f"\n--- Starting text generation ---")
logger.info(f"Prompt: {prompt}")
# Tokenize the input
input_ids = tokenizer.encode(prompt, return_tensors="pt").to(device)
# Run generation
with torch.no_grad():
outputs = model.generate(
input_ids,
max_length=100,
do_sample=True,
top_p=0.9,
temperature=0.7,
pad_token_id=tokenizer.pad_token_id
)
# Decode output
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
logger.info("\n--- Final Model Output ---")
print(generated_text)
logger.info("--- Done ---")
# ----------------------------------------------------
# 4. MODEL WEIGTH LOADING
# ----------------------------------------------------
try:
# loading moedl weight
model: YsnrfdForCausalLM = YsnrfdForCausalLM.from_pretrained(HF_MODEL_ID, config=config)
model.to(device)
model.eval()
logger.info(" MODEL AND WEIGHT ARE SUCCESFULY LOADED")
except Exception as e:
logger.error(f" MODEL LOADING ERROR OF Hub: {e}")
exit()
# ----------------------------------------------------
# 5. INFERENCE / RUN
# ----------------------------------------------------
prompt = "IN A SUNNY DAY"
logger.info(f"\n--- START TEXT GENERATION ---")
logger.info(f"پرامپت: {prompt}")
# TOKENIZING INPUTS
input_ids = tokenizer.encode(prompt, return_tensors="pt").to(device)
# RUN GENERATION
with torch.no_grad():
outputs = model.generate(
input_ids,
max_length=100,
do_sample=True,
top_p=0.9,
temperature=0.7,
pad_token_id=tokenizer.pad_token_id
)
# decoding output
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
logger.info("\n--- FINAL MODEL OUTPUT ---")
print(generated_text)
logger.info("--- END ---")
Training Data
wikitext2-raw-v1
Training Hyperparameters
- Training regime: float32
Evaluation
Not Yet
Testing Data, Factors & Metrics
ysnrfd en testing data
Testing Data
Not Yet
Summary
The Fisrt Persian LLM Trained From Scratch (Size Like SLM)
- Hardware Type: Nvidia Tesla T4
- Hours used: 3H
- Cloud Provider: Google Colab
Model Architecture and Objective
YSNRFD Architecture
Hardware
Nvidia Tesla T4
Software
Python Code, From Scratch, Pytorch
- Downloads last month
- 9