Instructions to use Arain119/sophia 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 Arain119/sophia 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 Arain119/sophia:Q4_K_M # Run inference directly in the terminal: llama cli -hf Arain119/sophia:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf Arain119/sophia:Q4_K_M # Run inference directly in the terminal: llama cli -hf Arain119/sophia:Q4_K_M
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 Arain119/sophia:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf Arain119/sophia:Q4_K_M
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 Arain119/sophia:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf Arain119/sophia:Q4_K_M
Use Docker
docker model run hf.co/Arain119/sophia:Q4_K_M
- LM Studio
- Jan
- Ollama
How to use Arain119/sophia with Ollama:
ollama run hf.co/Arain119/sophia:Q4_K_M
- Unsloth Desktop
- Docker Model Runner
How to use Arain119/sophia with Docker Model Runner:
docker model run hf.co/Arain119/sophia:Q4_K_M
- Lemonade
How to use Arain119/sophia with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull Arain119/sophia:Q4_K_M
Run and chat with the model
lemonade run user.sophia-Q4_K_M
List all available models
lemonade list
- Atomic Chat
Arain119
Sophia 1.0.0 — 1B K3-hybrid Chinese chat model (HF remote-code export + native package)
d53adc9 Download model_blocks.py from Arain119/sophia: direct link, hf CLI and curl.
- Browser
- Download file 3.71 kB
-
https://huggingface.co/Arain119/sophia/resolve/main/model_blocks.py
- Command line
-
hf download hf://Arain119/sophia/model_blocks.py
-
curl -L -o model_blocks.py https://huggingface.co/Arain119/sophia/resolve/main/model_blocks.py
3.71 kB
| # Generated by ml.integrations.export.runtime_packager.write_remote_code_bundle. | |
| # Exported for HuggingFace trust_remote_code loading. | |
| # This file is intentionally self-contained. | |
| from __future__ import annotations | |
| import torch | |
| from torch import nn | |
| from .model_attention import SophiaKDA, SophiaMLA | |
| from .model_config import ModelArgs | |
| from .model_ops import RMSNorm | |
| from .runtime_linear import RuntimeLinear | |
| class FeedForward(nn.Module): | |
| def __init__(self, args: ModelArgs) -> None: | |
| super().__init__() | |
| self.hidden = int(args.ffn_hidden) | |
| self.gate_softcap = float(args.situ_gate_softcap) | |
| self.up_softcap = float(args.situ_up_softcap) | |
| self.gate_up_proj = RuntimeLinear( | |
| int(args.dim), 2 * self.hidden, bias=False | |
| ) | |
| self.down_proj = RuntimeLinear(self.hidden, int(args.dim), bias=False) | |
| def forward(self, x: torch.Tensor) -> torch.Tensor: | |
| gate, up = self.gate_up_proj(x).split(self.hidden, dim=-1) | |
| bounded_gate = self.gate_softcap * torch.tanh(gate / self.gate_softcap) | |
| bounded_up = self.up_softcap * torch.tanh(up / self.up_softcap) | |
| return self.down_proj(bounded_gate * torch.sigmoid(gate) * bounded_up) | |
| class AttentionResidualMixer(nn.Module): | |
| """Content-dependent mixing over completed depth blocks and a partial block.""" | |
| def __init__(self, args: ModelArgs) -> None: | |
| super().__init__() | |
| self.norm = RMSNorm(args.dim, args.norm_eps) | |
| self.query = RuntimeLinear(args.dim, 1, bias=False) | |
| def forward( | |
| self, | |
| partial_block: torch.Tensor, | |
| completed_blocks: torch.Tensor, | |
| ) -> torch.Tensor: | |
| values = torch.cat((completed_blocks, partial_block.unsqueeze(2)), dim=2) | |
| keys = self.norm(values) | |
| score_weight = self.query.weight.squeeze(0).float() | |
| scores = torch.einsum("bsth,h->bst", keys.float(), score_weight) | |
| weights = scores.softmax(dim=2).unsqueeze(-1).to(dtype=values.dtype) | |
| return (weights * values).sum(dim=2).to(dtype=values.dtype) | |
| class SophiaBlock(nn.Module): | |
| def __init__(self, args: ModelArgs, layer_idx: int) -> None: | |
| super().__init__() | |
| self.layer_idx = int(layer_idx) | |
| self.layer_type = args.layer_type(self.layer_idx) | |
| self.attn_norm = RMSNorm(args.dim, args.norm_eps) | |
| self.attn = ( | |
| SophiaMLA(args) if self.layer_type == "mla" else SophiaKDA(args) | |
| ) | |
| self.ffn_norm = RMSNorm(args.dim, args.norm_eps) | |
| self.ffn = FeedForward(args) | |
| self.attn_res_block_size = int(args.attn_res_block_size) | |
| self.attn_residual = AttentionResidualMixer(args) | |
| self.ffn_residual = AttentionResidualMixer(args) | |
| def forward( | |
| self, | |
| partial_block: torch.Tensor, | |
| completed_blocks: torch.Tensor, | |
| *, | |
| start_pos: int = 0, | |
| ) -> tuple[torch.Tensor, torch.Tensor]: | |
| attn_input = self.attn_residual(partial_block, completed_blocks) | |
| if self.layer_idx % self.attn_res_block_size == 0: | |
| completed_blocks = torch.cat( | |
| (completed_blocks, partial_block.unsqueeze(2)), dim=2 | |
| ) | |
| partial_block = self.attn( | |
| self.attn_norm(attn_input), start_pos=int(start_pos) | |
| ) | |
| else: | |
| partial_block = partial_block + self.attn( | |
| self.attn_norm(attn_input), start_pos=int(start_pos) | |
| ) | |
| ffn_input = self.ffn_residual(partial_block, completed_blocks) | |
| partial_block = partial_block + self.ffn(self.ffn_norm(ffn_input)) | |
| return partial_block, completed_blocks | |
| __all__ = ["AttentionResidualMixer", "FeedForward", "SophiaBlock"] | |