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
8
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support