Downloads · 30 days
18
9% of all-time downloads
ysn-rfd/ysnrfd-base-V2
ysnrfd-base-V2 is a text generation model from ysn-rfd. Use it when you need the model to write or continue text. It is set up for transformers.
WARNINNGS: This Model IS Pre-Trained, in the future will be finetuned.
Downloads · 30 days
18
9% of all-time downloads
All-time downloads
209
Public
Repo size
1.8 GB
Likes
3
Public
Click a slice to open those files.
.pt1.2 GB · 66%
From the Hugging Face model README
WARNINNGS: This Model IS Pre-Trained, in the future will be finetuned.
The First Persian LLM By YSNRFD, This Model support Only English text Inputs, In The Future I Want Add Persian Language Support.
# 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
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 ---")
wikitext2-raw-v1
Not Yet
ysnrfd en testing data
Not Yet
The Fisrt Persian LLM Trained From Scratch (Size Like SLM)
YSNRFD Architecture
Nvidia Tesla T4
Python Code, From Scratch, Pytorch