Text Generation
Transformers
Safetensors
GGUF
Korean
English
llama
3b
korean
from-scratch
orpo
instruction-tuned
preference-aligned
fp8
b200
Eval Results (legacy)
text-generation-inference
Instructions to use pathcosmos/frankenstallm with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use pathcosmos/frankenstallm with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="pathcosmos/frankenstallm")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("pathcosmos/frankenstallm") model = AutoModelForCausalLM.from_pretrained("pathcosmos/frankenstallm", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use pathcosmos/frankenstallm 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 pathcosmos/frankenstallm:Q4_K_M # Run inference directly in the terminal: llama cli -hf pathcosmos/frankenstallm:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf pathcosmos/frankenstallm:Q4_K_M # Run inference directly in the terminal: llama cli -hf pathcosmos/frankenstallm: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 pathcosmos/frankenstallm:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf pathcosmos/frankenstallm: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 pathcosmos/frankenstallm:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf pathcosmos/frankenstallm:Q4_K_M
Use Docker
docker model run hf.co/pathcosmos/frankenstallm:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use pathcosmos/frankenstallm with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "pathcosmos/frankenstallm" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "pathcosmos/frankenstallm", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/pathcosmos/frankenstallm:Q4_K_M
- SGLang
How to use pathcosmos/frankenstallm with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "pathcosmos/frankenstallm" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "pathcosmos/frankenstallm", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "pathcosmos/frankenstallm" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "pathcosmos/frankenstallm", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Ollama
How to use pathcosmos/frankenstallm with Ollama:
ollama run hf.co/pathcosmos/frankenstallm:Q4_K_M
- Unsloth Studio
How to use pathcosmos/frankenstallm 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 pathcosmos/frankenstallm 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 pathcosmos/frankenstallm to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for pathcosmos/frankenstallm to start chatting
- Docker Model Runner
How to use pathcosmos/frankenstallm with Docker Model Runner:
docker model run hf.co/pathcosmos/frankenstallm:Q4_K_M
- Lemonade
How to use pathcosmos/frankenstallm with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull pathcosmos/frankenstallm:Q4_K_M
Run and chat with the model
lemonade run user.frankenstallm-Q4_K_M
List all available models
lemonade list
- Atomic Chat
| """ | |
| train/utils.py — Training utility functions. | |
| Provides: | |
| get_cosine_schedule_with_warmup : LambdaLR scheduler with linear warmup + cosine decay | |
| save_checkpoint : Persist model/optimizer/scheduler state to disk | |
| load_checkpoint : Restore state from a saved checkpoint directory | |
| get_grad_norm : Compute total L2 gradient norm across all parameters | |
| setup_ddp : Initialise NCCL distributed process group | |
| cleanup_ddp : Tear down distributed process group | |
| is_main_process : True when this process is rank 0 (or non-distributed) | |
| """ | |
| from __future__ import annotations | |
| import math | |
| import os | |
| import shutil | |
| from pathlib import Path | |
| from typing import Optional, Tuple | |
| import numpy as np | |
| import torch | |
| import torch.distributed as dist | |
| import yaml | |
| from torch.optim import Optimizer | |
| from torch.optim.lr_scheduler import LambdaLR | |
| # --------------------------------------------------------------------------- | |
| # Learning-rate schedule | |
| # --------------------------------------------------------------------------- | |
| def get_cosine_schedule_with_warmup( | |
| optimizer: Optimizer, | |
| warmup_steps: int, | |
| total_steps: int, | |
| min_lr_ratio: float = 0.1, | |
| ) -> LambdaLR: | |
| """ | |
| Create a LambdaLR scheduler with: | |
| - Linear warmup: lr scales from 0 → 1 over [0, warmup_steps) | |
| - Cosine decay: lr scales from 1 → min_lr_ratio over [warmup_steps, total_steps] | |
| Args: | |
| optimizer: The wrapped optimizer. | |
| warmup_steps: Number of linear-warmup steps. | |
| total_steps: Total number of training steps. | |
| min_lr_ratio: Minimum lr as a fraction of the peak lr (default 0.1). | |
| Returns: | |
| A LambdaLR scheduler instance. | |
| """ | |
| if warmup_steps < 0: | |
| raise ValueError(f"warmup_steps must be >= 0, got {warmup_steps}") | |
| if total_steps <= 0: | |
| raise ValueError(f"total_steps must be > 0, got {total_steps}") | |
| if not (0.0 <= min_lr_ratio <= 1.0): | |
| raise ValueError(f"min_lr_ratio must be in [0, 1], got {min_lr_ratio}") | |
| def lr_lambda(current_step: int) -> float: | |
| # Linear warmup phase. | |
| if current_step < warmup_steps: | |
| return float(current_step) / float(max(1, warmup_steps)) | |
| # After total_steps, hold at min_lr_ratio. | |
| if current_step >= total_steps: | |
| return min_lr_ratio | |
| # Cosine decay phase. | |
| decay_steps = total_steps - warmup_steps | |
| progress = float(current_step - warmup_steps) / float(max(1, decay_steps)) | |
| cosine_factor = 0.5 * (1.0 + math.cos(math.pi * progress)) | |
| # Scale cosine output from [0, 1] into [min_lr_ratio, 1]. | |
| return min_lr_ratio + (1.0 - min_lr_ratio) * cosine_factor | |
| return LambdaLR(optimizer, lr_lambda) | |
| # --------------------------------------------------------------------------- | |
| # Checkpoint save / load | |
| # --------------------------------------------------------------------------- | |
| def save_checkpoint( | |
| model: torch.nn.Module, | |
| optimizer: Optimizer, | |
| scheduler: LambdaLR, | |
| step: int, | |
| loss: float, | |
| path: str | Path, | |
| suffix: str | None = None, | |
| ) -> Path: | |
| """ | |
| Save a training checkpoint to ``path/checkpoint-{step:07d}/``. | |
| Saves: | |
| - model.pt : model state_dict | |
| - optimizer.pt : optimizer state_dict | |
| - scheduler.pt : scheduler state_dict | |
| - train_state.pt : step and loss scalars | |
| - config.yaml : model LMConfig (if the model exposes a ``.config`` attribute) | |
| Handles both plain ``nn.Module`` and DDP-wrapped models by unwrapping | |
| via ``.module`` when present. | |
| Args: | |
| model: The model (plain or DDP-wrapped). | |
| optimizer: The optimizer. | |
| scheduler: The LR scheduler. | |
| step: Current training step (used in directory name). | |
| loss: Current loss value (stored for reference). | |
| path: Root checkpoint directory. | |
| Returns: | |
| Path to the created checkpoint sub-directory. | |
| """ | |
| dir_name = f"checkpoint-{suffix}" if suffix else f"checkpoint-{step:07d}" | |
| ckpt_dir = Path(path) / dir_name | |
| tmp_dir = Path(path) / f".tmp_{dir_name}" | |
| # Write to temp directory first for crash safety | |
| if tmp_dir.exists(): | |
| shutil.rmtree(tmp_dir) | |
| tmp_dir.mkdir(parents=True, exist_ok=True) | |
| raw_model: torch.nn.Module = getattr(model, "module", model) | |
| torch.save(raw_model.state_dict(), tmp_dir / "model.pt") | |
| torch.save(optimizer.state_dict(), tmp_dir / "optimizer.pt") | |
| torch.save(scheduler.state_dict(), tmp_dir / "scheduler.pt") | |
| import random as _random | |
| train_state = { | |
| "step": step, | |
| "loss": loss, | |
| "rng_state": { | |
| "python": _random.getstate(), | |
| "numpy": np.random.get_state(), | |
| "torch_cpu": torch.random.get_rng_state(), | |
| "torch_cuda": torch.cuda.get_rng_state_all(), | |
| }, | |
| } | |
| torch.save(train_state, tmp_dir / "train_state.pt") | |
| # Persist the model config when available. | |
| if hasattr(raw_model, "config"): | |
| cfg = raw_model.config | |
| if hasattr(cfg, "to_dict"): | |
| config_dict = cfg.to_dict() | |
| else: | |
| # Fallback: try __dict__ for plain dataclasses. | |
| config_dict = { | |
| k: v for k, v in vars(cfg).items() if not k.startswith("_") | |
| } | |
| with open(tmp_dir / "config.yaml", "w", encoding="utf-8") as f: | |
| yaml.safe_dump(config_dict, f, default_flow_style=False, sort_keys=False) | |
| # Atomic swap: rename old → trash, tmp → final, delete trash | |
| trash_dir = Path(path) / f".trash_{dir_name}" | |
| if trash_dir.exists(): | |
| shutil.rmtree(trash_dir) | |
| if ckpt_dir.exists(): | |
| ckpt_dir.rename(trash_dir) | |
| tmp_dir.rename(ckpt_dir) | |
| if trash_dir.exists(): | |
| shutil.rmtree(trash_dir) | |
| # Clean up old checkpoints (keep recent N + best) | |
| cleanup_old_checkpoints(Path(path)) | |
| return ckpt_dir | |
| def cleanup_old_checkpoints(path: Path, keep: int = 5) -> None: | |
| """Remove old checkpoints, keeping the most recent `keep` plus checkpoint-best.""" | |
| ckpts = sorted( | |
| [d for d in path.glob("checkpoint-[0-9]*") if d.is_dir()], | |
| key=lambda d: d.stat().st_mtime, | |
| ) | |
| for old in ckpts[:-keep]: | |
| shutil.rmtree(old) | |
| def load_checkpoint( | |
| path: str | Path, | |
| model: torch.nn.Module, | |
| optimizer: Optional[Optimizer] = None, | |
| scheduler: Optional[LambdaLR] = None, | |
| ) -> Tuple[int, float]: | |
| """ | |
| Load a checkpoint from a directory created by :func:`save_checkpoint`. | |
| The model weights are always restored. Optimizer and scheduler states are | |
| only restored when the corresponding objects are provided. | |
| Args: | |
| path: Path to the checkpoint directory (e.g. ``checkpoints/checkpoint-0001000``). | |
| model: Model to load weights into (plain or DDP-wrapped). | |
| optimizer: Optional optimizer to restore state into. | |
| scheduler: Optional LR scheduler to restore state into. | |
| Returns: | |
| ``(step, loss)`` — the training step and loss recorded at save time. | |
| """ | |
| ckpt_dir = Path(path) | |
| if not ckpt_dir.is_dir(): | |
| raise FileNotFoundError(f"Checkpoint directory not found: {ckpt_dir}") | |
| # Unwrap DDP model if necessary. | |
| raw_model: torch.nn.Module = getattr(model, "module", model) | |
| # Determine the device the model lives on. | |
| try: | |
| device = next(raw_model.parameters()).device | |
| except StopIteration: | |
| device = torch.device("cpu") | |
| raw_model.load_state_dict( | |
| torch.load(ckpt_dir / "model.pt", map_location=device, weights_only=True) | |
| ) | |
| if optimizer is not None: | |
| optimizer.load_state_dict( | |
| torch.load(ckpt_dir / "optimizer.pt", map_location=device, weights_only=True) | |
| ) | |
| if scheduler is not None: | |
| scheduler.load_state_dict( | |
| torch.load(ckpt_dir / "scheduler.pt", map_location=device, weights_only=True) | |
| ) | |
| train_state = torch.load( | |
| ckpt_dir / "train_state.pt", map_location="cpu", weights_only=True | |
| ) | |
| step: int = int(train_state["step"]) | |
| loss: float = float(train_state["loss"]) | |
| # Restore RNG states if available (for exact resume reproducibility) | |
| rng_state = train_state.get("rng_state") | |
| if rng_state is not None: | |
| import random as _random | |
| try: | |
| _random.setstate(rng_state["python"]) | |
| np.random.set_state(rng_state["numpy"]) | |
| torch.random.set_rng_state(rng_state["torch_cpu"]) | |
| torch.cuda.set_rng_state_all(rng_state["torch_cuda"]) | |
| except Exception as e: | |
| print(f"[WARN] RNG state restore failed (non-fatal): {e}") | |
| return step, loss | |
| # --------------------------------------------------------------------------- | |
| # Gradient utilities | |
| # --------------------------------------------------------------------------- | |
| def get_grad_norm(model: torch.nn.Module) -> float: | |
| """ | |
| Compute the total L2 norm of all parameter gradients. | |
| Uses a single GPU kernel + one GPU-CPU sync instead of one sync per | |
| parameter (the naive loop approach). Only parameters with non-None | |
| ``.grad`` attribute contribute. | |
| Args: | |
| model: The model (plain or DDP-wrapped). | |
| Returns: | |
| Scalar float — the global gradient L2 norm. | |
| """ | |
| raw_model: torch.nn.Module = getattr(model, "module", model) | |
| grads = [p.grad.detach().float() for p in raw_model.parameters() if p.grad is not None] | |
| if not grads: | |
| return 0.0 | |
| # Stack individual norms and compute the L2 norm of norms — single sync. | |
| return torch.stack([g.norm(2) for g in grads]).norm(2).item() | |
| # --------------------------------------------------------------------------- | |
| # Distributed training helpers | |
| # --------------------------------------------------------------------------- | |
| def setup_ddp() -> Tuple[int, int, int, torch.device]: | |
| """ | |
| Initialise the NCCL distributed process group for DDP training. | |
| Reads ``RANK``, ``LOCAL_RANK``, and ``WORLD_SIZE`` from the environment | |
| (set automatically by ``torchrun``). | |
| Returns: | |
| ``(rank, local_rank, world_size, device)`` | |
| """ | |
| rank = int(os.environ["RANK"]) | |
| local_rank = int(os.environ["LOCAL_RANK"]) | |
| world_size = int(os.environ["WORLD_SIZE"]) | |
| # Limit CPU thread count per process to avoid contention across 8 ranks. | |
| # 72 cores / 8 ranks = 9; use 4 to leave headroom for DataLoader workers. | |
| os.environ.setdefault("OMP_NUM_THREADS", "4") | |
| os.environ.setdefault("MKL_NUM_THREADS", "4") | |
| import datetime as _dt | |
| dist.init_process_group( | |
| backend="nccl", | |
| timeout=_dt.timedelta(seconds=7200), # 2h for large checkpoint loads | |
| ) | |
| torch.cuda.set_device(local_rank) | |
| device = torch.device(f"cuda:{local_rank}") | |
| return rank, local_rank, world_size, device | |
| def cleanup_ddp() -> None: | |
| """Tear down the distributed process group (call at end of training).""" | |
| if dist.is_available() and dist.is_initialized(): | |
| dist.destroy_process_group() | |
| def is_main_process() -> bool: | |
| """ | |
| Return ``True`` when this process is rank 0 or when running without DDP. | |
| Reads the ``RANK`` environment variable; if it is absent the process is | |
| assumed to be the sole process (rank 0). | |
| """ | |
| return int(os.environ.get("RANK", "0")) == 0 | |