Text Generation
PyTorch
GGUF
Hindi
English
foundational-model
scratch-training
llama-architecture
hinglish
ramayana
mahabharata
Instructions to use namanadep/foundational-llama-scratch-epic-model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use namanadep/foundational-llama-scratch-epic-model with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf namanadep/foundational-llama-scratch-epic-model # Run inference directly in the terminal: llama cli -hf namanadep/foundational-llama-scratch-epic-model
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf namanadep/foundational-llama-scratch-epic-model # Run inference directly in the terminal: llama cli -hf namanadep/foundational-llama-scratch-epic-model
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf namanadep/foundational-llama-scratch-epic-model # Run inference directly in the terminal: ./llama-cli -hf namanadep/foundational-llama-scratch-epic-model
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf namanadep/foundational-llama-scratch-epic-model # Run inference directly in the terminal: ./build/bin/llama-cli -hf namanadep/foundational-llama-scratch-epic-model
Use Docker
docker model run hf.co/namanadep/foundational-llama-scratch-epic-model
- LM Studio
- Jan
- vLLM
How to use namanadep/foundational-llama-scratch-epic-model with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "namanadep/foundational-llama-scratch-epic-model" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "namanadep/foundational-llama-scratch-epic-model", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/namanadep/foundational-llama-scratch-epic-model
- Ollama
How to use namanadep/foundational-llama-scratch-epic-model with Ollama:
ollama run hf.co/namanadep/foundational-llama-scratch-epic-model
- Unsloth Studio
How to use namanadep/foundational-llama-scratch-epic-model with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for namanadep/foundational-llama-scratch-epic-model to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for namanadep/foundational-llama-scratch-epic-model to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for namanadep/foundational-llama-scratch-epic-model to start chatting
- Docker Model Runner
How to use namanadep/foundational-llama-scratch-epic-model with Docker Model Runner:
docker model run hf.co/namanadep/foundational-llama-scratch-epic-model
- Lemonade
How to use namanadep/foundational-llama-scratch-epic-model with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull namanadep/foundational-llama-scratch-epic-model
Run and chat with the model
lemonade run user.foundational-llama-scratch-epic-model-{{QUANT_TAG}}List all available models
lemonade list
- Atomic Chat
| import json | |
| import hashlib | |
| import os | |
| import sys | |
| import torch | |
| from tokenizers import Tokenizer | |
| sys.path.append("/data/foundational_model") | |
| from model.model import ModelConfig, Transformer | |
| phrases = [ | |
| "namaste, aap kaise hain?", | |
| "ramayana kisne likhi hai?", | |
| "mahabharata me arjun kaun the?", | |
| "kya kar rahe ho?", | |
| "shri ram ke pita ka naam kya tha?", | |
| "gita me bhagwan krishna ne kya kaha?", | |
| "aaj ka mausam kaisa hai?", | |
| "mujhe ek achhi kahani sunao.", | |
| "ravan ka rajya kahan tha?", | |
| "pandav kitne bhai the?", | |
| "dharma ka kya matlab hai?", | |
| "kaise ho bhai?", | |
| "life me khush kaise rahe?", | |
| "hanuman ji ke bare me batao.", | |
| "karna kaun tha?", | |
| "aaj ka din kaisa raha?", | |
| "sita ji ka janma kahan hua tha?", | |
| "bheeshma pitamah kaun the?", | |
| "ek accha vichar bataiye.", | |
| "alvida, phir milenge!" | |
| ] | |
| def sample_next_token(logits, temperature=0.7, top_p=0.9, generated_ids=[], no_repeat_ngram_size=2): | |
| logits = logits.clone() | |
| # N-gram blocking to eliminate token repetition | |
| if len(generated_ids) >= no_repeat_ngram_size: | |
| prev_ngram = tuple(generated_ids[-(no_repeat_ngram_size - 1):]) | |
| for i in range(len(generated_ids) - no_repeat_ngram_size + 1): | |
| if tuple(generated_ids[i:i + no_repeat_ngram_size - 1]) == prev_ngram: | |
| forbidden_token = generated_ids[i + no_repeat_ngram_size - 1] | |
| logits[forbidden_token] = -float("Inf") | |
| # Apply temperature | |
| logits = logits / temperature | |
| sorted_logits, sorted_indices = torch.sort(logits, descending=True) | |
| cumulative_probs = torch.cumsum(torch.softmax(sorted_logits, dim=-1), dim=-1) | |
| sorted_indices_to_remove = cumulative_probs > top_p | |
| sorted_indices_to_remove[..., 1:] = sorted_indices_to_remove[..., :-1].clone() | |
| sorted_indices_to_remove[..., 0] = 0 | |
| indices_to_remove = sorted_indices[sorted_indices_to_remove] | |
| logits[indices_to_remove] = -float("Inf") | |
| probs = torch.softmax(logits, dim=-1) | |
| return torch.multinomial(probs, num_samples=1).item() | |
| def generate_direct(): | |
| device = "cuda" if torch.cuda.is_available() else "cpu" | |
| tokenizer_path = "/data/foundational_model/tokenizer/hinglish_tokenizer.json" | |
| checkpoint_path = "/data/foundational_model/checkpoints/model_125m_final.pt" | |
| print(f"Loading PyTorch scratch model on {device}...") | |
| tokenizer = Tokenizer.from_file(tokenizer_path) | |
| config = ModelConfig( | |
| vocab_size=16384, | |
| dim=256, | |
| n_layers=6, | |
| n_heads=8, | |
| n_kv_heads=8, | |
| max_seq_len=128 | |
| ) | |
| model = Transformer(config).to(device) | |
| model.load_state_dict(torch.load(checkpoint_path, map_location=device)) | |
| model.eval() | |
| results = [] | |
| response_texts = [] | |
| print(f"Evaluating {len(phrases)} phrases on Scratch Model with 2-Gram Blocking...\n") | |
| torch.manual_seed(42) | |
| for idx, phrase in enumerate(phrases, 1): | |
| prompt_tokens = [4] + tokenizer.encode(f" {phrase}").ids + [5] | |
| generated = prompt_tokens[:] | |
| for _ in range(30): | |
| context = generated[-128:] | |
| logits = model(torch.tensor([context], dtype=torch.long, device=device))[0, -1, :] | |
| gen_ids = generated[len(prompt_tokens):] | |
| next_tok = sample_next_token(logits, temperature=0.7, top_p=0.9, generated_ids=gen_ids, no_repeat_ngram_size=2) | |
| if next_tok in (2, 3): # </s> or <pad> | |
| break | |
| generated.append(next_tok) | |
| resp_text = tokenizer.decode(generated[len(prompt_tokens):]).strip() | |
| print(f"[{idx:02d}/{len(phrases)}] Prompt: '{phrase}'") | |
| print(f" Response: '{resp_text}'\n") | |
| results.append({ | |
| "index": idx, | |
| "prompt": phrase, | |
| "response": resp_text | |
| }) | |
| response_texts.append(resp_text) | |
| combined = "\n---RESPONSE_SEP---\n".join(response_texts) | |
| md5_hash = hashlib.md5(combined.encode("utf-8")).hexdigest() | |
| print("=" * 60) | |
| print(f"MD5 Checksum of Scratch Model 20 Responses: {md5_hash}") | |
| print("=" * 60) | |
| out_file = "/data/foundational_model/eval/evaluation_results.json" | |
| with open(out_file, "w", encoding="utf-8") as f: | |
| json.dump({ | |
| "md5": md5_hash, | |
| "results": results | |
| }, f, indent=2, ensure_ascii=False) | |
| print(f"Saved results to {out_file}") | |
| if __name__ == "__main__": | |
| generate_direct() | |