Instructions to use coderecode95/KJH with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use coderecode95/KJH with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="coderecode95/KJH") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("coderecode95/KJH") model = AutoModelForCausalLM.from_pretrained("coderecode95/KJH", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use coderecode95/KJH with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "coderecode95/KJH" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "coderecode95/KJH", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/coderecode95/KJH
- SGLang
How to use coderecode95/KJH 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 "coderecode95/KJH" \ --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": "coderecode95/KJH", "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 "coderecode95/KJH" \ --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": "coderecode95/KJH", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use coderecode95/KJH with Docker Model Runner:
docker model run hf.co/coderecode95/KJH
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="coderecode95/KJH")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages)# Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("coderecode95/KJH")
model = AutoModelForCausalLM.from_pretrained("coderecode95/KJH", device_map="auto")
messages = [
{"role": "user", "content": "Who are you?"},
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))kjh-model
Scratch pretrained. Llama-style architecture. No Meta weights used.
๊น์ฌํ์ด ๊ฐ์ธ์ ์ผ๋ก ์ฐ๊ตฌยทํ์ต ๋ชฉ์ ์ผ๋ก ๊ฐ๋ฐํ ๋ก์ปฌ ํ๊ตญ์ด ์ธ์ด๋ชจ๋ธ์ด๋ค. RAG(๊ฒ์ ์ฆ๊ฐ ์์ฑ) ํ๊ฒฝ์์, ์ฐพ์์จ ์๋ฃ๋ฅผ ๊ทผ๊ฑฐ๋ก ๋ตํ๋๋ก ๋ง๋ค์ด์ก๋ค.
1. ์ด ๋ชจ๋ธ์ ์ถ์ฒ โ ์ ๋๋ค ์ด๊ธฐํ๋ถํฐ ํ์ตํ๋
์ด ๋ชจ๋ธ์ ๊ฐ์ค์น๋ ๋๋ค ์ด๊ธฐํ์์ ์ง์ ์ฌ์ ํ์ต(scratch pretrained) ํ ๊ฒ์ด๋ค. Meta ์ Llama ์ฒดํฌํฌ์ธํธ๋ฅผ ๋ด๋ ค๋ฐ์ ํ์ธํ๋ํ๊ฑฐ๋ ์ด์ด ํ์ตํ ๊ฒ์ด ์๋๊ณ , ์ด๋ค ํํ๋ก๋ Llama ๊ฐ์ค์น๋ฅผ ํฌํจํ์ง ์๋๋ค.
architectures / model_type ์ด "llama" ์ธ ์ด์
config.json ์
"architectures": ["LlamaForCausalLM"],
"model_type": "llama"
๋ ์ถ์ฒ ํ๊ธฐ๊ฐ ์๋๋ผ ๊ตฌ์กฐ ํ๊ธฐ๋ค. transformers ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์ด ๊ฐ์ค์น ํ
์๋ฅผ
์ด๋ค forward ์ฝ๋๋ก ๋๋ฆด์ง ๊ณ ๋ฅด๋ ๋ก๋ ์ง์์์ผ ๋ฟ, "์ด ๋ชจ๋ธ์ด Meta ์์ ์๋ค"๋
๋ป์ด ์๋๋ค.
Pre-norm Transformer + RMSNorm + SwiGLU + RoPE + GQA ๋ผ๋ ๊ณต๊ฐ๋(๋๊ตฌ๋ ์ธ ์ ์๋)
์ค๊ณ ์กฐํฉ์ ์ฐ๋ฉด, transformers ์์์์ ๊ตฌํ ์ด๋ฆ์ด llama ๊ฐ ๋๋ค. ์ด ์กฐํฉ ์์ฒด๋
Meta ์ ์ ์ ๋ฌผ์ด ์๋๋ผ ์ฌ๋ฌ ๋
ผ๋ฌธ์์ ์กฐํฉํด ์ฐ๋ ํ์ค ๊ตฌ์ฑ์ด๋ค. ๊ทธ๋์ TinyLlama,
OpenLLaMA, SmolLM ์ฒ๋ผ ์์ ํ ์์ฒด์ ์ผ๋ก ์ฌ์ ํ์ตํ ๋ชจ๋ธ๋ค๋ ๊ฐ์ ์ด์ ๋ก
LlamaForCausalLM ์ ๊ทธ๋๋ก ์ด๋ค โ ์ด ํ๋ก์ ํธ๋ง์ ์์ธ์ ์ธ ํ๊ธฐ๊ฐ ์๋๋ค.
์ด ํ๊ธฐ๋ฅผ ์ปค์คํ
ํด๋์ค ์ด๋ฆ์ผ๋ก ๋ฐ๊พธ๋ ค๋ฉด auto_map + modeling_*.py ๋ฅผ ์ง์
์์ฑํด ๋ฃ๊ณ trust_remote_code=True ๋ก ๋ถ๋ฌ์ผ ํ๋๋ฐ, ๊ทธ๋ฌ๋ฉด vLLM ยท llama.cpp ยท
GGUF ๋ณํ ๊ฐ์ ์ธ๋ถ ๋๊ตฌ์์ ํธํ์ด ๋๋ถ๋ถ ๋๊ธด๋ค. ๊ทธ๋์ ์๋์ ์ผ๋ก ํ์ค ํ๊ธฐ๋ฅผ
์ ์งํ๋ค. (architectures, model_type ์ ๋ณ๊ฒฝํ์ง ์๋๋ค.)
2. ์ฌ์
| ํญ๋ชฉ | ๊ฐ |
|---|---|
| ์ด ํ๋ผ๋ฏธํฐ | ์ฝ 172M (๋ณธ์ฒด 107M + ์๋ฒ ๋ฉ/์ถ๋ ฅ์ธต 66M) |
| ๋ ์ด์ด | 12 |
| hidden / intermediate | 1024 / 2048 |
| attention head | 16 (KV head 4, GQA) |
| head_dim | 64 |
| ์ปจํ ์คํธ ๊ธธ์ด | 4096 |
| vocab | 32,001 (์์ฒด ํ ํฌ๋์ด์ + ํน์ํ ํฐ 1) |
| dtype | float16 |
| ํ์ต ๋ฐฉ์ | ๋๋ค ์ด๊ธฐํ โ scratch pretraining โ RAG ํ์ SFT |
ํฌ๊ธฐ๋ถํฐ๊ฐ Meta Llama ๊ณ์ด(์ต์ 1B)์ ์กด์ฌํ์ง ์๋ ๊ตฌ์ฑ์ด๋ค. ์ฐธ๊ณ ๋ก ํ๋ผ๋ฏธํฐ๋ฅผ
0.1B ๊ธ์ผ๋ก ์ค์ฌ ๋ถ๋ฅด๋ ๊ฒฝ์ฐ, ์๋ฒ ๋ฉ/์ถ๋ ฅ์ธต์ ์ ์ธํ ๋ณธ์ฒด(107M) ๊ธฐ์ค์ด๋ค โ ์ ํํ
์ด๋์ 172M ์ด๋ค.
3. ์ฐ๋ ๋ฒ โ ๋ฐ๋์ [์๋ฃ] / [์ง๋ฌธ] ํ์์ผ๋ก ๋ฌผ์ ๊ฒ
์ด ๋ชจ๋ธ์ ๊ทผ๊ฑฐ ๋ฌธ์์ ์ง๋ฌธ์ ์๋ ํ์์ผ๋ก ๊ฐ์ธ ์ฃผ๋ ๊ฒ์ ์ ์ ๋ก SFT ๋์๋ค. ์ด ํ์์ ์งํค์ง ์์ผ๋ฉด ์๋ ๊ฒ๋ ์ง์ด๋ด๋ ๋น๋๊ฐ ํฌ๊ฒ ๋์ด๋๋ค.
[์๋ฃ]
(๊ฒ์ํด ์๊ฑฐ๋ ์์ผ๋ก ๋ฃ์ ๊ทผ๊ฑฐ ๋ฌธ์ฅ๋ค)
[์ง๋ฌธ] (์ฌ์ฉ์์ ์ง๋ฌธ)
Transformers ๋ก ์ง์ ๋ถ๋ฌ ์ฐ๊ธฐ
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
token = "hf_xxxxxxxxxxxx" # ๋ณธ์ธ ํ ํฐ
MODEL = "coderecode95/KJH" # ์ค์ ๋ฆฌํฌ์งํ ๋ฆฌ ๊ฒฝ๋ก๋ก ๋ฐ๊ฟ ๊ฒ
tok = AutoTokenizer.from_pretrained(MODEL, token=token)
model = AutoModelForCausalLM.from_pretrained(MODEL, token=token, dtype=torch.float16).to("cuda").eval()
# context = "" ์ฐธ๊ณ ์๋ฃ๋ฅผ ๋ฃ์ ๊ฒฝ์ฐ ์๋ฃ๋ฅผ ๊ธฐ๋ฐํ์ฌ ๋ต๋ณํฉ๋๋ค.
question = "๊ฑด๊ฐ์ ์ํด์๋ ์ด๋ป๊ฒ ํด์ผํ ๊น?"
# prompt = f"[์๋ฃ]\n{context}\n\n[์ง๋ฌธ] {question}"
prompt = f"{question}"
messages = [{"role": "user", "content": prompt}]
inputs = tok.apply_chat_template(
messages,
add_generation_prompt=True,
return_tensors="pt",
return_dict=True, # ๋ช
์์ ์ผ๋ก dict(BatchEncoding) ๋ฐํํ๋๋ก
).to("cuda")
output = model.generate(
**inputs,
max_new_tokens=200,
do_sample=True,
temperature=0.55,
top_p=0.85,
repetition_penalty=1.15,
no_repeat_ngram_size=4,
pad_token_id=tok.pad_token_id or tok.eos_token_id,
)
print(tok.decode(output[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
์ ๋์ฝ๋ฉ ํ๋ผ๋ฏธํฐ(temperature=0.55, repetition_penalty=1.15,
no_repeat_ngram_size=4)๋ generation_config.json ์๋ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ๋ค์ด ์์ผ๋ฏ๋ก,
๋ณ๋๋ก ์ง์ ํ์ง ์๊ณ model.generate(input_ids, attention_mask=...) ๋ง ํธ์ถํด๋
๊ฐ์ ๊ฐ์ด ์ ์ฉ๋๋ค.
๊ทผ๊ฑฐ ์์ด ๋ฌผ์ผ๋ฉด ์ด๋ป๊ฒ ๋๋
[์๋ฃ] ๋ธ๋ก ์์ด ์ง๋ฌธ๋ง ๋์ง๋ฉด("[์ง๋ฌธ] ์ธ์ข
๋์์ ๋๊ตฌ์ผ?" ๋๋ ๊ทธ๋ฅ
ํ๋ฌธ ์ง๋ฌธ) ๋ชจ๋ธ์ด ๊ฐ๊ณ ์๋ ์์ ์ง์์ผ๋ก ๋ต์ ์๋ํ๋ฉฐ, ์ด ๊ฒฝ์ฐ ์ฌ์ค ๊ด๊ณ๋ฅผ ์ง์ด๋ผ
ํ๋ฅ ์ด ๋๋ ท์ด ์ฌ๋ผ๊ฐ๋ค. ์ ํํ ๋ต์ด ํ์ํ ์ง๋ฌธ์ ๋ฐ๋์ ๊ทผ๊ฑฐ๋ฅผ ํจ๊ป ์ค๋ค.
์ฑํ ํ ํ๋ฆฟ
<|im_start|>{role}
{content}<|endoftext|>
<|im_start|>assistant
ChatML ๊ณผ ์ ์ฌํ ํ์์ด๋ฉฐ, tokenizer_config.json ์ chat_template.jinja ๋ก
๋ฑ๋ก๋์ด ์์ด apply_chat_template() ์ ๊ทธ๋๋ก ์ฐ๋ฉด ๋๋ค.
4. ๋ฌด์์ ์ํ๊ณ , ๋ฌด์์ ๋ชปํ๋๊ฐ (์ค์ธก ๊ธฐ์ค)
์์ ๋ชจ๋ธ์ด๋ผ๋ ์ ์ ์จ๊ธฐ์ง ์๋๋ค. ์๋ฐฑ ๊ฐ์ ์ง๋ฌธ์ ์ง์ ๋๋ ค ํ์ธํ ๊ฒฐ๊ณผ๋ค.
์ํ๋ ๊ฒ
- ๊ทผ๊ฑฐ๋ฅผ ๊ทธ๋๋ก ์ฎ๊ฒจ ์งง๊ฒ ๋ตํ๊ธฐ โ
[์๋ฃ]์ ์ค์ ๋ต์ด ์๋ ์ฌ์คํ ์ง๋ฌธ ("OO ํ ์ด๋ธ์ ์ด๋ค ์ปฌ๋ผ์ด ์์ด?", "์ค๋ฆฝ๋ ๋๊ฐ ์ธ์ ์ผ?") - ์ ํด์ง ํ์์ ๋ฐ๋ณต ์์ โ ์ธ์ฌ, ์๊ธฐ์๊ฐ, ์ ํํ๋ ๋ฌธ์ ์์ฝ
- ํ๊ตญ์ด ๋ฌธ์ฅ ์์ฑ โ ํ์ต ๋ฐ์ดํฐ๊ฐ ํ๊ตญ์ด ์์ฃผ๋ผ ์ด ๋ฒ์์์๋ ์์ฐ์ค๋ฝ๋ค
๋ชปํ๋ ๊ฒ
- ์์ด ์ง๋ฌธ โ ํ๊ตญ์ด ์ ์ฉ ๋ฐ์ดํฐ๋ก ํ์ต๋์ด ์์ด๋ก ๋ฌผ์ผ๋ฉด ๋ต์ด ๋ฌด๋์ง๋ค (๋ฌธ๋ฒ์ด ๊นจ์ง๊ฑฐ๋ ๊ด๋ จ ์๋ ํ ํฐ์ ๋์ด๋๋๋ค).
- ๊ธด ์ ์ฐจํ ๋ต๋ณ โ ๋ ์ํผ, ์ค์น ์์์ฒ๋ผ ๋จ๊ณ ์์๋ฅผ ์ง์ผ์ผ ํ๋ ๋ต๋ณ์ ์์๊ฐ ๋ค์์ด๊ฑฐ๋ ์๋ ๋จ๊ณ๋ฅผ ์ง์ด๋ธ๋ค.
- ๋ฉํฐํด ๋งฅ๋ฝ ์ ์ง โ ๋ช ํด๋ง ์ง๋๋ ์ด์ ๋ํ ๋ด์ฉ์ ์๋ฑํ๊ฒ ๋์ง์ด ๋ต์ด ๋ฌด๋์ง๋ ๊ฒฝํฅ์ด ๋๋ ทํ๋ค. ๋งค ์ง๋ฌธ์ ํ์ํ ์ ๋ณด(์ฃผ์ด ๋ฑ)๋ฅผ ๋ค์ ๋ฃ๋ ๊ฒ์ ๊ถ์ฅํ๋ค.
- ๊ณ ์ ๋ช ์ฌยท์ซ์๋ฅผ ์ ํํ ๊ทธ๋๋ก ๋ฒ ๋ผ๊ธฐ โ ๊ทผ๊ฑฐ์ ์๋ ์ด๋ฆ์ด๋ ์ซ์๋ฅผ ๋น์ทํ์ง๋ง ํ๋ฆฐ ๊ฐ์ผ๋ก ๋ฐ๊ฟ ์ฐ๋ ๊ฒฝ์ฐ๊ฐ ์๋ค (์: ํ์ฌ๋ช ์ ์์ ์ด ํ๋ ๋น ์ง, ์ฐ๋๊ฐ ํ๋ ์๋ฆฌ ๋ฐ๋). ๋ฒ์ ยท์ฌ๋ฌด์ ์ผ๋ก ์ ํํด์ผ ํ๋ ์ซ์ยท๊ณ ์ ๋ช ์ฌ๋ ๋ชจ๋ธ ์ถ๋ ฅ์ ๊ทธ๋๋ก ์ ๋ขฐํ์ง ๋ง๊ณ ์๋ฌธ ๋์กฐ๋ฅผ ๊ถ์ฅํ๋ค.
- SQLยท์ฝ๋ ์์ฑ โ ํ์ต ๋ฒ์ ๋ฐ์ด๋ผ ๋ฌธ๋ฒ์ด ๊นจ์ง ์ฝ๋๋ฅผ ๋ธ๋ค. (์ฐธ๊ณ : ์ด ๋ชจ๋ธ์ ์ค์ ๋ก ์๋น์ค์ ์น์ ๋๋ SQL ์์ฑ์ ๋ชจ๋ธ์ ๋งก๊ธฐ์ง ์๊ณ , ์คํค๋ง ์ ๋ณด๋ฅผ ์ฝ๋๋ก ํ์ฑํด ๊ท์น ๊ธฐ๋ฐ์ผ๋ก ์กฐ๋ฆฝํ๋ ๋ฐฉ์์ ํจ๊ป ์ผ๋ค.)
์์ฝ
์ด ๋ชจ๋ธ ๋จ๋ ์ผ๋ก๋ "๋ฌด์์ด๋ ์ ๋ตํ๋ ์ด์์คํดํธ"๊ฐ ์๋๋ค. ๊ทผ๊ฑฐ๋ฅผ ๋ถ์ฌ ์ข์ ์ง๋ฌธ์ ์งง๊ฒ ๋ตํ๊ฒ ํ๋ ์ฉ๋๋ก ์ค๊ณ๋์๊ณ , ๊ทธ ๋ฒ์๋ฅผ ๋ฒ์ด๋๋ฉด ์ฑ๋ฅ์ด ๊ธ๊ฒฉํ ๋จ์ด์ง๋ค. ์ ํ๋๊ฐ ์ค์ํ ๋ถ๋ถ(์ซ์ ๊ณ์ฐ, SQL, ์คํค๋ง ์กฐํ ๋ฑ)์ ๋ชจ๋ธ์ด ์๋๋ผ ์ฃผ๋ณ ์ฝ๋๊ฐ ๋ด๋นํ๊ณ , ๋ชจ๋ธ์ "์ฐพ์์จ ๋ฌธ์ฅ์ ์์ฐ์ค๋ฌ์ด ํ๊ตญ์ด๋ก ํ์ด ์ค๋ช ํ๋" ์ญํ ์ ์ง์ค์ํค๋ ๊ฒ์ ๊ถ์ฅํ๋ค.
5. ํ์ต ๊ฐ์
- 1๋จ๊ณ โ ์ฌ์ ํ์ต(pretraining): ๋๋ค ์ด๊ธฐํ ๊ฐ์ค์น์์ ์์ํด ํ๊ตญ์ด ํ ์คํธ๋ก ์ฒ์๋ถํฐ ํ์ต.
- 2๋จ๊ณ โ RAG ํ์ SFT:
[์๋ฃ]\n(๊ทผ๊ฑฐ)\n\n[์ง๋ฌธ] (์ง๋ฌธ)ํ์์ ๋ํ ๋ฐ์ดํฐ๋ก ์ง๋ ๋ฏธ์ธ์กฐ์ . ๊ทผ๊ฑฐ ์์ด ๋ฌป๋ ์ผ๋ฐ ๋ํยท์ธ์ฌยท์๊ธฐ์๊ฐ๋ ์ผ๋ถ ํฌํจ.
6. ๋ผ์ด์ ์ค
Apache License 2.0. ์์
์ ์ด์ฉ์ ํฌํจํด ์์ ๋กญ๊ฒ ์ฌ์ฉยท์์ ยท์ฌ๋ฐฐํฌํ ์ ์์ผ๋ฉฐ,
์์ ์์ ํ์๋ฅผ ๋จ๊ฒจ์ผ ํ๋ค. ์์ธํ ์กฐ๊ฑด์ ๋ฆฌํฌ์งํ ๋ฆฌ์ LICENSE ํ์ผ์ ์ฐธ๊ณ ํ ๊ฒ.
7. ์ธ์ฉ
@misc{kjh-model,
title = {kjh-model: A Scratch-Pretrained Korean Small Language Model for RAG},
author = {Kim, Jaehyeon},
year = {2026}
}
8. ์ค์ ์ฌ์ฉ ์์
์ด ๋ชจ๋ธ์ RAG ํ์ดํ๋ผ์ธ์ ์ ์ฉํด ์ฑ๋ฅ์ ํ์ธํ ๋ฐ๋ชจ ์์์ ๋๋ค.
- Downloads last month
- 55
# Gated model: Login with a HF token with gated access permission hf auth login