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 hf_cache.py from Arain119/sophia: direct link, hf CLI and curl.
- Browser
- Download file 4.9 kB
-
https://huggingface.co/Arain119/sophia/resolve/main/hf_cache.py
- Command line
-
hf download hf://Arain119/sophia/hf_cache.py
-
curl -L -o hf_cache.py https://huggingface.co/Arain119/sophia/resolve/main/hf_cache.py
4.9 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. | |
| """HF cache adapter owned by the Sophia HF adapter layer.""" | |
| from __future__ import annotations | |
| import weakref | |
| import torch | |
| from transformers.cache_utils import Cache, CacheLayerMixin | |
| from .cache_decode import RuntimeCacheState | |
| from .model_state import LayerCacheSnapshot, RuntimeCacheSnapshot | |
| CacheState = RuntimeCacheState | |
| class SophiaCacheLayer(CacheLayerMixin): | |
| def __init__( | |
| self, | |
| *, | |
| name: str, | |
| snapshot: LayerCacheSnapshot, | |
| seq_length: int, | |
| max_cache_shape: int, | |
| ): | |
| super().__init__() | |
| self.name = str(name) | |
| self.snapshot = snapshot.clone() | |
| self.payload = { | |
| str(key): value | |
| for key, value in self.snapshot.to_payload(prefix=self.name).items() | |
| } | |
| self._seq_length = int(seq_length) | |
| self._max_cache_shape = int(max_cache_shape) | |
| representative = next( | |
| ( | |
| value | |
| for _name, value in self.snapshot.tensor_fields() | |
| if value is not None | |
| ), | |
| None, | |
| ) | |
| if representative is not None: | |
| self.keys = representative.unsqueeze(1) | |
| self.values = self.keys | |
| self.is_initialized = True | |
| def lazy_initialization(self, key_states: torch.Tensor, value_states: torch.Tensor) -> None: | |
| del key_states, value_states | |
| raise NotImplementedError("SophiaCacheLayer is immutable and cannot be initialized lazily") | |
| def update( | |
| self, | |
| key_states: torch.Tensor, | |
| value_states: torch.Tensor, | |
| cache_kwargs: dict[str, object] | None = None, | |
| ) -> tuple[torch.Tensor, torch.Tensor]: | |
| del key_states, value_states, cache_kwargs | |
| raise NotImplementedError("SophiaCacheLayer is an exported runtime snapshot and does not support update()") | |
| def get_mask_sizes(self, cache_position: torch.Tensor) -> tuple[int, int]: | |
| del cache_position | |
| return self.get_seq_length(), 0 | |
| def get_seq_length(self) -> int: | |
| return self._seq_length | |
| def get_max_cache_shape(self) -> int: | |
| return self._max_cache_shape | |
| def max_batch_size(self) -> int: | |
| if self.keys is None: | |
| return 0 | |
| return int(self.keys.size(0)) | |
| def max_cache_len(self) -> int: | |
| return int(self._max_cache_shape) | |
| def device(self) -> torch.device: | |
| if self.keys is None: | |
| return torch.device("cpu") | |
| return self.keys.device | |
| class SophiaCache(Cache): | |
| def __init__( | |
| self, | |
| *, | |
| owner: object, | |
| cache: RuntimeCacheSnapshot, | |
| cache_pos: int, | |
| batch_size: int, | |
| ): | |
| self._cache = cache.clone() | |
| self._cache_pos = int(cache_pos) | |
| self._batch_size = int(batch_size) | |
| self._owner_ref = weakref.ref(owner) | |
| super().__init__(layers=self._build_layers()) | |
| def _build_layers(self) -> list[SophiaCacheLayer]: | |
| owner = self._owner_ref() | |
| max_cache_shape = ( | |
| -1 | |
| if owner is None | |
| else int(getattr(owner.config, "max_position_embeddings", 0) or -1) | |
| ) | |
| return [ | |
| SophiaCacheLayer( | |
| name=name, | |
| snapshot=snapshot, | |
| seq_length=self._cache_pos, | |
| max_cache_shape=max_cache_shape, | |
| ) | |
| for name, snapshot in self._cache.named_snapshots() | |
| ] | |
| def to_runtime_cache(self) -> RuntimeCacheSnapshot: | |
| return self._cache.clone() | |
| def get_seq_length(self, layer_idx: int = 0) -> int: | |
| del layer_idx | |
| return int(self._cache_pos) | |
| def get_max_cache_shape(self, layer_idx: int = 0) -> int: | |
| del layer_idx | |
| owner = self._owner_ref() | |
| if owner is None: | |
| return -1 | |
| return int(getattr(owner.config, "max_position_embeddings", 0) or -1) | |
| def cache_pos(self) -> int: | |
| return int(self._cache_pos) | |
| def batch_size(self) -> int: | |
| return int(self._batch_size) | |
| def cache_state_from_past_key_values( | |
| past_key_values: SophiaCache | None, | |
| ) -> CacheState | None: | |
| if past_key_values is None: | |
| return None | |
| if isinstance(past_key_values, SophiaCache): | |
| return CacheState( | |
| cache=past_key_values.to_runtime_cache(), | |
| batch_size=int(past_key_values.batch_size), | |
| cache_pos=int(past_key_values.cache_pos), | |
| ) | |
| raise TypeError("past_key_values must be a SophiaCache returned by the HF adapter") | |
| __all__ = [ | |
| "CacheState", | |
| "SophiaCache", | |
| "SophiaCacheLayer", | |
| "cache_state_from_past_key_values", | |
| ] | |