Text Generation
Transformers
Safetensors
PyTorch
English
Portuguese
kern_qwen3_moe
kern
sparse-moe
experimental
custom_code
conversational
Instructions to use Project-KERN/KERN-Lab-0.5-624M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Project-KERN/KERN-Lab-0.5-624M with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Project-KERN/KERN-Lab-0.5-624M", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Project-KERN/KERN-Lab-0.5-624M", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Project-KERN/KERN-Lab-0.5-624M with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Project-KERN/KERN-Lab-0.5-624M" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Project-KERN/KERN-Lab-0.5-624M", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Project-KERN/KERN-Lab-0.5-624M
- SGLang
How to use Project-KERN/KERN-Lab-0.5-624M 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 "Project-KERN/KERN-Lab-0.5-624M" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Project-KERN/KERN-Lab-0.5-624M", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "Project-KERN/KERN-Lab-0.5-624M" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Project-KERN/KERN-Lab-0.5-624M", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Project-KERN/KERN-Lab-0.5-624M with Docker Model Runner:
docker model run hf.co/Project-KERN/KERN-Lab-0.5-624M
File size: 2,638 Bytes
52ce59d 40d562c 52ce59d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | """Optional localhost-only Gradio interface for text continuation."""
import argparse
from pathlib import Path
import torch
from transformers import AutoTokenizer
from modeling_kern_qwen06b_v1 import load_kern_qwen06b_v1
def build_interface(model_dir: Path, device: str):
import gradio as gr
dtype = torch.bfloat16 if device == "cuda" and torch.cuda.is_bf16_supported() else torch.float32
model, _ = load_kern_qwen06b_v1(model_dir, device=device, dtype=dtype)
tokenizer = AutoTokenizer.from_pretrained(
model_dir, config=model.config, local_files_only=True, trust_remote_code=False
)
def continue_text(prompt: str, max_new_tokens: int) -> str:
if not prompt.strip():
raise gr.Error("Enter a text prefix to continue.")
inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False).to(model.device)
prompt_tokens = inputs["input_ids"].shape[-1]
if prompt_tokens + int(max_new_tokens) > model.config.max_position_embeddings:
raise gr.Error("The prompt and requested continuation exceed the configured context.")
with torch.inference_mode():
output = model.generate(
**inputs,
max_new_tokens=int(max_new_tokens),
do_sample=False,
use_cache=True,
pad_token_id=tokenizer.pad_token_id,
)
return tokenizer.decode(output[0, prompt_tokens:], skip_special_tokens=True)
return gr.Interface(
fn=continue_text,
inputs=[
gr.Textbox(label="Text to continue", lines=4, value="A group of researchers discovered"),
gr.Slider(1, 256, value=48, step=1, label="New tokens"),
],
outputs=gr.Textbox(label="Continuation", lines=6),
title="KERN-Lab-0.5-624M",
description=(
"Experimental base model for text continuation. Runs locally. "
"[Official model card](https://huggingface.co/Project-KERN/KERN-Lab-0.5-624M)."
),
api_name="generate",
analytics_enabled=False,
)
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--model-dir", type=Path, default=Path(__file__).resolve().parent)
parser.add_argument("--device", choices=("auto", "cpu", "cuda"), default="auto")
options = parser.parse_args()
device = options.device
if device == "auto":
device = "cuda" if torch.cuda.is_available() else "cpu"
build_interface(options.model_dir, device).launch(server_name="127.0.0.1", share=False)
if __name__ == "__main__":
main()
|