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 decoder_full.py from Arain119/sophia: direct link, hf CLI and curl.
- Browser
- Download file 5.29 kB
-
https://huggingface.co/Arain119/sophia/resolve/394c875663ffe708f08ac49e705d826e73de585a/decoder_full.py
- Command line
-
hf download hf://Arain119/sophia@394c875663ffe708f08ac49e705d826e73de585a/decoder_full.py
-
curl -L -o decoder_full.py https://huggingface.co/Arain119/sophia/resolve/394c875663ffe708f08ac49e705d826e73de585a/decoder_full.py
5.29 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 .input_mask import is_all_ones_mask, slice_valid_tokens | |
| from .decoder_types import DecoderConfig, DecoderCoreModel | |
| from .decoder_loss import ( | |
| loss_stats, | |
| mean_cross_entropy_loss, | |
| ) | |
| from .decoder_loss_forward import forward_loss | |
| def validate_decoder_inputs( | |
| *, | |
| input_ids: torch.Tensor | None, | |
| labels: torch.Tensor | None, | |
| compute_loss: bool, | |
| ) -> torch.Tensor: | |
| if input_ids is None: | |
| raise ValueError("input_ids is required") | |
| if input_ids.dim() != 2: | |
| raise ValueError("input_ids must be [B,T]") | |
| if bool(compute_loss) and labels is None: | |
| raise ValueError("compute_loss=True requires labels") | |
| return input_ids | |
| def forward_full_with_mask( | |
| *, | |
| runtime_model: DecoderCoreModel, | |
| vocab_size: int, | |
| input_ids: torch.Tensor, | |
| attention_mask: torch.Tensor | None, | |
| output_weight: torch.Tensor, | |
| ) -> torch.Tensor: | |
| if attention_mask is None or is_all_ones_mask(attention_mask): | |
| return runtime_model.forward_full(input_ids) | |
| rows = slice_valid_tokens(input_ids, attention_mask) | |
| logits = output_weight.new_zeros( | |
| (int(input_ids.size(0)), int(input_ids.size(1)), int(vocab_size)) | |
| ) | |
| for batch_index, (start, end, row_tokens) in enumerate(rows): | |
| row_logits = runtime_model.forward_full(row_tokens) | |
| logits[batch_index, start:end] = row_logits[0] | |
| return logits | |
| def masked_loss( | |
| *, | |
| runtime_model: DecoderCoreModel, | |
| config: DecoderConfig, | |
| input_ids: torch.Tensor, | |
| attention_mask: torch.Tensor, | |
| labels: torch.Tensor, | |
| vocab_size: int, | |
| output_weight: torch.Tensor, | |
| ) -> tuple[torch.Tensor, torch.Tensor]: | |
| rows = slice_valid_tokens(input_ids, attention_mask) | |
| logits = output_weight.new_zeros( | |
| (int(input_ids.size(0)), int(input_ids.size(1)), int(vocab_size)) | |
| ) | |
| loss_sum = output_weight.new_zeros(()) | |
| count = output_weight.new_zeros(()) | |
| for batch_index, (start, end, row_tokens) in enumerate(rows): | |
| row_labels = labels[batch_index : batch_index + 1, start:end] | |
| row_logits = runtime_model.forward_full(row_tokens) | |
| logits[batch_index, start:end] = row_logits[0] | |
| row_sum, row_count = loss_stats(row_logits, row_labels, label_offset=0) | |
| loss_sum = loss_sum + row_sum | |
| count = count + row_count | |
| loss = torch.where( | |
| count > 0, | |
| loss_sum / count.clamp_min(1.0), | |
| output_weight.new_zeros(()), | |
| ) | |
| return logits, loss | |
| def forward_decoder_full( | |
| *, | |
| runtime_model: DecoderCoreModel, | |
| config: DecoderConfig, | |
| training: bool, | |
| input_ids: torch.Tensor, | |
| attention_mask: torch.Tensor | None, | |
| labels: torch.Tensor | None, | |
| compute_loss: bool, | |
| output_weight: torch.Tensor, | |
| ) -> tuple[torch.Tensor | None, torch.Tensor | None]: | |
| if bool(compute_loss): | |
| loss = forward_loss( | |
| runtime_model=runtime_model, | |
| config=config, | |
| training=bool(training), | |
| input_ids=input_ids, | |
| attention_mask=attention_mask, | |
| labels=labels, | |
| output_weight=output_weight, | |
| ) | |
| return loss, None | |
| loss, logits = forward_full( | |
| runtime_model=runtime_model, | |
| config=config, | |
| training=bool(training), | |
| input_ids=input_ids, | |
| attention_mask=attention_mask, | |
| labels=labels, | |
| ) | |
| if labels is not None and bool(training) and not bool(config.return_logits_in_train): | |
| logits = None | |
| return loss, logits | |
| def forward_full( | |
| *, | |
| runtime_model: DecoderCoreModel, | |
| config: DecoderConfig, | |
| training: bool, | |
| input_ids: torch.Tensor, | |
| attention_mask: torch.Tensor | None, | |
| labels: torch.Tensor | None, | |
| ) -> tuple[torch.Tensor | None, torch.Tensor | None]: | |
| del training | |
| if labels is not None: | |
| if attention_mask is not None and not is_all_ones_mask(attention_mask): | |
| logits, loss = masked_loss( | |
| runtime_model=runtime_model, | |
| config=config, | |
| input_ids=input_ids, | |
| attention_mask=attention_mask, | |
| labels=labels, | |
| vocab_size=int(getattr(config, "vocab_size", 0)), | |
| output_weight=runtime_model.output.weight, | |
| ) | |
| return loss, logits | |
| logits = forward_full_with_mask( | |
| runtime_model=runtime_model, | |
| vocab_size=int(config.vocab_size), | |
| input_ids=input_ids, | |
| attention_mask=attention_mask, | |
| output_weight=runtime_model.output.weight, | |
| ) | |
| return mean_cross_entropy_loss(logits, labels, label_offset=0), logits | |
| logits = forward_full_with_mask( | |
| runtime_model=runtime_model, | |
| vocab_size=int(config.vocab_size), | |
| input_ids=input_ids, | |
| attention_mask=attention_mask, | |
| output_weight=runtime_model.output.weight, | |
| ) | |
| return None, logits | |
| __all__ = [ | |
| "forward_full_with_mask", | |
| "forward_decoder_full", | |
| "forward_full", | |
| "masked_loss", | |
| "validate_decoder_inputs", | |
| ] | |