Instructions to use KORMo-Team/KORMo-10B-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use KORMo-Team/KORMo-10B-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="KORMo-Team/KORMo-10B-base", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("KORMo-Team/KORMo-10B-base", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use KORMo-Team/KORMo-10B-base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "KORMo-Team/KORMo-10B-base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "KORMo-Team/KORMo-10B-base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/KORMo-Team/KORMo-10B-base
- SGLang
How to use KORMo-Team/KORMo-10B-base 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 "KORMo-Team/KORMo-10B-base" \ --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": "KORMo-Team/KORMo-10B-base", "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 "KORMo-Team/KORMo-10B-base" \ --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": "KORMo-Team/KORMo-10B-base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use KORMo-Team/KORMo-10B-base with Docker Model Runner:
docker model run hf.co/KORMo-Team/KORMo-10B-base
Update _modeling_kormo.py
Browse files- _modeling_kormo.py +6 -15
_modeling_kormo.py
CHANGED
|
@@ -94,13 +94,13 @@ def rotate_half(x):
|
|
| 94 |
x1 = x[..., : x.shape[-1] // 2]
|
| 95 |
x2 = x[..., x.shape[-1] // 2 :]
|
| 96 |
return torch.cat((-x2, x1), dim=-1)
|
| 97 |
-
|
| 98 |
def copy_(tensor: torch.Tensor, other: torch.Tensor) -> torch.Tensor:
|
| 99 |
if not getattr(tensor, "_is_hf_initialized", False):
|
| 100 |
with torch.no_grad():
|
| 101 |
return tensor.copy_(other)
|
| 102 |
return tensor
|
| 103 |
-
|
| 104 |
class Attention(nn.Module):
|
| 105 |
"""Multi-headed attention from 'Attention Is All You Need' paper"""
|
| 106 |
|
|
@@ -261,7 +261,7 @@ class RotaryEmbedding(nn.Module):
|
|
| 261 |
base ** (torch.arange(0, dim, 2, dtype=torch.int64).to(device=device, dtype=torch.float) / dim)
|
| 262 |
)
|
| 263 |
return inv_freq, attention_factor
|
| 264 |
-
|
| 265 |
@torch.no_grad()
|
| 266 |
@dynamic_rope_update # power user: used with advanced RoPE types (e.g. dynamic rope)
|
| 267 |
def forward(self, x, position_ids):
|
|
@@ -277,10 +277,6 @@ class RotaryEmbedding(nn.Module):
|
|
| 277 |
return cos, sin
|
| 278 |
|
| 279 |
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
class KORMoPreTrainedModel(PreTrainedModel):
|
| 285 |
config_class = KORMoConfig
|
| 286 |
base_model_prefix = "model"
|
|
@@ -316,8 +312,7 @@ class KORMoPreTrainedModel(PreTrainedModel):
|
|
| 316 |
)
|
| 317 |
buffer_value, _ = rope_fn(module.config)
|
| 318 |
copy_(module.inv_freq, buffer_value)
|
| 319 |
-
copy_(module.original_inv_freq, buffer_value)
|
| 320 |
-
|
| 321 |
|
| 322 |
class KORMoModel(KORMoPreTrainedModel):
|
| 323 |
def __init__(self, config: KORMoConfig):
|
|
@@ -390,14 +385,12 @@ class KORMoModel(KORMoPreTrainedModel):
|
|
| 390 |
position_ids = cache_position.unsqueeze(0)
|
| 391 |
|
| 392 |
if self.config._attn_implementation == "flash_attention_3_doc":
|
| 393 |
-
### TODO: 수정필요
|
| 394 |
causal_mask = attention_mask
|
| 395 |
else:
|
| 396 |
causal_mask = create_causal_mask(
|
| 397 |
config=self.config,
|
| 398 |
-
|
| 399 |
attention_mask=attention_mask,
|
| 400 |
-
cache_position=cache_position,
|
| 401 |
past_key_values=past_key_values,
|
| 402 |
position_ids=position_ids,
|
| 403 |
)
|
|
@@ -525,6 +518,4 @@ class KORMoForCausalLM(KORMoPreTrainedModel, GenerationMixin):
|
|
| 525 |
past_key_values=outputs.past_key_values,
|
| 526 |
hidden_states=outputs.hidden_states,
|
| 527 |
attentions=outputs.attentions,
|
| 528 |
-
)
|
| 529 |
-
|
| 530 |
-
|
|
|
|
| 94 |
x1 = x[..., : x.shape[-1] // 2]
|
| 95 |
x2 = x[..., x.shape[-1] // 2 :]
|
| 96 |
return torch.cat((-x2, x1), dim=-1)
|
| 97 |
+
|
| 98 |
def copy_(tensor: torch.Tensor, other: torch.Tensor) -> torch.Tensor:
|
| 99 |
if not getattr(tensor, "_is_hf_initialized", False):
|
| 100 |
with torch.no_grad():
|
| 101 |
return tensor.copy_(other)
|
| 102 |
return tensor
|
| 103 |
+
|
| 104 |
class Attention(nn.Module):
|
| 105 |
"""Multi-headed attention from 'Attention Is All You Need' paper"""
|
| 106 |
|
|
|
|
| 261 |
base ** (torch.arange(0, dim, 2, dtype=torch.int64).to(device=device, dtype=torch.float) / dim)
|
| 262 |
)
|
| 263 |
return inv_freq, attention_factor
|
| 264 |
+
|
| 265 |
@torch.no_grad()
|
| 266 |
@dynamic_rope_update # power user: used with advanced RoPE types (e.g. dynamic rope)
|
| 267 |
def forward(self, x, position_ids):
|
|
|
|
| 277 |
return cos, sin
|
| 278 |
|
| 279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
class KORMoPreTrainedModel(PreTrainedModel):
|
| 281 |
config_class = KORMoConfig
|
| 282 |
base_model_prefix = "model"
|
|
|
|
| 312 |
)
|
| 313 |
buffer_value, _ = rope_fn(module.config)
|
| 314 |
copy_(module.inv_freq, buffer_value)
|
| 315 |
+
copy_(module.original_inv_freq, buffer_value)
|
|
|
|
| 316 |
|
| 317 |
class KORMoModel(KORMoPreTrainedModel):
|
| 318 |
def __init__(self, config: KORMoConfig):
|
|
|
|
| 385 |
position_ids = cache_position.unsqueeze(0)
|
| 386 |
|
| 387 |
if self.config._attn_implementation == "flash_attention_3_doc":
|
|
|
|
| 388 |
causal_mask = attention_mask
|
| 389 |
else:
|
| 390 |
causal_mask = create_causal_mask(
|
| 391 |
config=self.config,
|
| 392 |
+
inputs_embeds=inputs_embeds,
|
| 393 |
attention_mask=attention_mask,
|
|
|
|
| 394 |
past_key_values=past_key_values,
|
| 395 |
position_ids=position_ids,
|
| 396 |
)
|
|
|
|
| 518 |
past_key_values=outputs.past_key_values,
|
| 519 |
hidden_states=outputs.hidden_states,
|
| 520 |
attentions=outputs.attentions,
|
| 521 |
+
)
|
|
|
|
|
|