Instructions to use sakthi07/haney-gpt-v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- llama-cpp-python
How to use sakthi07/haney-gpt-v2 with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="sakthi07/haney-gpt-v2", filename="haney-gpt-v2-f16.gguf", )
output = llm( "Once upon a time,", max_tokens=512, echo=True ) print(output)
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use sakthi07/haney-gpt-v2 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 sakthi07/haney-gpt-v2:F16 # Run inference directly in the terminal: llama cli -hf sakthi07/haney-gpt-v2:F16
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf sakthi07/haney-gpt-v2:F16 # Run inference directly in the terminal: llama cli -hf sakthi07/haney-gpt-v2:F16
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 sakthi07/haney-gpt-v2:F16 # Run inference directly in the terminal: ./llama-cli -hf sakthi07/haney-gpt-v2:F16
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 sakthi07/haney-gpt-v2:F16 # Run inference directly in the terminal: ./build/bin/llama-cli -hf sakthi07/haney-gpt-v2:F16
Use Docker
docker model run hf.co/sakthi07/haney-gpt-v2:F16
- LM Studio
- Jan
- Ollama
How to use sakthi07/haney-gpt-v2 with Ollama:
ollama run hf.co/sakthi07/haney-gpt-v2:F16
- Unsloth Studio
How to use sakthi07/haney-gpt-v2 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 sakthi07/haney-gpt-v2 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 sakthi07/haney-gpt-v2 to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for sakthi07/haney-gpt-v2 to start chatting
- Atomic Chat new
- Docker Model Runner
How to use sakthi07/haney-gpt-v2 with Docker Model Runner:
docker model run hf.co/sakthi07/haney-gpt-v2:F16
- Lemonade
How to use sakthi07/haney-gpt-v2 with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull sakthi07/haney-gpt-v2:F16
Run and chat with the model
lemonade run user.haney-gpt-v2-F16
List all available models
lemonade list
| import math | |
| from dataclasses import dataclass | |
| import torch | |
| import torch.nn as nn | |
| import torch.nn.functional as F | |
| class GPTConfig: | |
| vocab_size: int = 50257 | |
| block_size: int = 512 | |
| n_layer: int = 24 | |
| n_head: int = 20 | |
| n_embd: int = 1280 | |
| dropout: float = 0.1 | |
| bias: bool = False | |
| class CausalSelfAttention(nn.Module): | |
| def __init__(self, config): | |
| super().__init__() | |
| assert config.n_embd % config.n_head == 0 | |
| self.n_head = config.n_head | |
| self.n_embd = config.n_embd | |
| self.head_dim = config.n_embd // config.n_head | |
| self.c_attn = nn.Linear( | |
| config.n_embd, | |
| 3 * config.n_embd, | |
| bias=config.bias | |
| ) | |
| self.c_proj = nn.Linear( | |
| config.n_embd, | |
| config.n_embd, | |
| bias=config.bias | |
| ) | |
| self.attn_dropout = nn.Dropout(config.dropout) | |
| self.resid_dropout = nn.Dropout(config.dropout) | |
| def forward(self, x): | |
| B, T, C = x.size() | |
| qkv = self.c_attn(x) | |
| q, k, v = qkv.split(self.n_embd, dim=2) | |
| q = q.view( | |
| B, | |
| T, | |
| self.n_head, | |
| self.head_dim | |
| ).transpose(1, 2) | |
| k = k.view( | |
| B, | |
| T, | |
| self.n_head, | |
| self.head_dim | |
| ).transpose(1, 2) | |
| v = v.view( | |
| B, | |
| T, | |
| self.n_head, | |
| self.head_dim | |
| ).transpose(1, 2) | |
| y = F.scaled_dot_product_attention( | |
| q, | |
| k, | |
| v, | |
| dropout_p=self.attn_dropout.p if self.training else 0.0, | |
| is_causal=True | |
| ) | |
| y = y.transpose(1, 2).contiguous() | |
| y = y.view(B, T, C) | |
| y = self.c_proj(y) | |
| y = self.resid_dropout(y) | |
| return y | |
| class MLP(nn.Module): | |
| def __init__(self, config): | |
| super().__init__() | |
| self.c_fc = nn.Linear( | |
| config.n_embd, | |
| 4 * config.n_embd, | |
| bias=config.bias | |
| ) | |
| self.gelu = nn.GELU() | |
| self.c_proj = nn.Linear( | |
| 4 * config.n_embd, | |
| config.n_embd, | |
| bias=config.bias | |
| ) | |
| self.dropout = nn.Dropout(config.dropout) | |
| def forward(self, x): | |
| x = self.c_fc(x) | |
| x = self.gelu(x) | |
| x = self.c_proj(x) | |
| x = self.dropout(x) | |
| return x | |
| class Block(nn.Module): | |
| def __init__(self, config): | |
| super().__init__() | |
| self.ln_1 = nn.LayerNorm(config.n_embd) | |
| self.attn = CausalSelfAttention(config) | |
| self.ln_2 = nn.LayerNorm(config.n_embd) | |
| self.mlp = MLP(config) | |
| def forward(self, x): | |
| x = x + self.attn( | |
| self.ln_1(x) | |
| ) | |
| x = x + self.mlp( | |
| self.ln_2(x) | |
| ) | |
| return x | |
| class GPT(nn.Module): | |
| def __init__(self, config): | |
| super().__init__() | |
| self.config = config | |
| self.transformer = nn.ModuleDict( | |
| dict( | |
| wte=nn.Embedding( | |
| config.vocab_size, | |
| config.n_embd | |
| ), | |
| wpe=nn.Embedding( | |
| config.block_size, | |
| config.n_embd | |
| ), | |
| drop=nn.Dropout( | |
| config.dropout | |
| ), | |
| h=nn.ModuleList( | |
| [ | |
| Block(config) | |
| for _ in range(config.n_layer) | |
| ] | |
| ), | |
| ln_f=nn.LayerNorm( | |
| config.n_embd | |
| ), | |
| ) | |
| ) | |
| self.lm_head = nn.Linear( | |
| config.n_embd, | |
| config.vocab_size, | |
| bias=False | |
| ) | |
| self.transformer.wte.weight = self.lm_head.weight | |
| self.apply(self._init_weights) | |
| print( | |
| f"Model Parameters: " | |
| f"{self.get_num_params()/1e6:.2f}M" | |
| ) | |
| def _init_weights(self, module): | |
| if isinstance(module, nn.Linear): | |
| nn.init.normal_( | |
| module.weight, | |
| mean=0.0, | |
| std=0.02 | |
| ) | |
| if module.bias is not None: | |
| nn.init.zeros_(module.bias) | |
| elif isinstance(module, nn.Embedding): | |
| nn.init.normal_( | |
| module.weight, | |
| mean=0.0, | |
| std=0.02 | |
| ) | |
| def get_num_params(self): | |
| return sum( | |
| p.numel() | |
| for p in self.parameters() | |
| ) | |
| def forward( | |
| self, | |
| idx, | |
| targets=None | |
| ): | |
| B, T = idx.size() | |
| assert ( | |
| T <= self.config.block_size | |
| ), "Sequence too long" | |
| pos = torch.arange( | |
| 0, | |
| T, | |
| device=idx.device | |
| ) | |
| tok_emb = self.transformer.wte(idx) | |
| pos_emb = self.transformer.wpe(pos) | |
| x = tok_emb + pos_emb | |
| x = self.transformer.drop(x) | |
| for block in self.transformer.h: | |
| x = block(x) | |
| x = self.transformer.ln_f(x) | |
| logits = self.lm_head(x) | |
| loss = None | |
| if targets is not None: | |
| loss = F.cross_entropy( | |
| logits.reshape( | |
| -1, | |
| logits.size(-1) | |
| ), | |
| targets.reshape(-1) | |
| ) | |
| return logits, loss | |
| def generate( | |
| self, | |
| idx, | |
| max_new_tokens, | |
| temperature=1.0, | |
| top_k=50 | |
| ): | |
| for _ in range(max_new_tokens): | |
| idx_cond = idx[ | |
| :, | |
| -self.config.block_size: | |
| ] | |
| logits, _ = self(idx_cond) | |
| logits = logits[:, -1, :] | |
| logits = logits / temperature | |
| if top_k is not None: | |
| v, _ = torch.topk( | |
| logits, | |
| min( | |
| top_k, | |
| logits.size(-1) | |
| ) | |
| ) | |
| logits[ | |
| logits < v[:, [-1]] | |
| ] = -float("inf") | |
| probs = F.softmax( | |
| logits, | |
| dim=-1 | |
| ) | |
| idx_next = torch.multinomial( | |
| probs, | |
| num_samples=1 | |
| ) | |
| idx = torch.cat( | |
| (idx, idx_next), | |
| dim=1 | |
| ) | |
| return idx | |
| if __name__ == "__main__": | |
| config = GPTConfig() | |
| model = GPT(config) | |
| print( | |
| f"Total Parameters: " | |
| f"{model.get_num_params():,}" | |
| ) |