Instructions to use pfnet/plamo-2-1b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use pfnet/plamo-2-1b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="pfnet/plamo-2-1b", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("pfnet/plamo-2-1b", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use pfnet/plamo-2-1b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "pfnet/plamo-2-1b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "pfnet/plamo-2-1b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/pfnet/plamo-2-1b
- SGLang
How to use pfnet/plamo-2-1b 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 "pfnet/plamo-2-1b" \ --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": "pfnet/plamo-2-1b", "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 "pfnet/plamo-2-1b" \ --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": "pfnet/plamo-2-1b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use pfnet/plamo-2-1b with Docker Model Runner:
docker model run hf.co/pfnet/plamo-2-1b
Update modeling_plamo.py
#8
by shmurai - opened
- modeling_plamo.py +16 -2
modeling_plamo.py
CHANGED
|
@@ -19,6 +19,7 @@ import torch
|
|
| 19 |
from torch import nn
|
| 20 |
from torch.nn import functional as F
|
| 21 |
from transformers import PretrainedConfig, PreTrainedModel
|
|
|
|
| 22 |
from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast
|
| 23 |
|
| 24 |
|
|
@@ -327,7 +328,8 @@ class Plamo2Cache(torch.nn.Module):
|
|
| 327 |
if sequence_length is not None
|
| 328 |
else layer_cache.key.shape[2]
|
| 329 |
)
|
| 330 |
-
|
|
|
|
| 331 |
return sequence_length
|
| 332 |
|
| 333 |
def get_max_length(self) -> int | None:
|
|
@@ -1387,7 +1389,7 @@ class Plamo2Model(Plamo2PreTrainedModel):
|
|
| 1387 |
input_ids: Optional[torch.LongTensor] = None,
|
| 1388 |
attention_mask: Optional[torch.Tensor] = None,
|
| 1389 |
position_ids: Optional[torch.Tensor] = None,
|
| 1390 |
-
past_key_values: Optional[Plamo2Cache] = None,
|
| 1391 |
inputs_embeds: Optional[torch.Tensor] = None,
|
| 1392 |
image_features: Optional[torch.Tensor] = None,
|
| 1393 |
use_cache: Optional[bool] = None,
|
|
@@ -1419,6 +1421,18 @@ class Plamo2Model(Plamo2PreTrainedModel):
|
|
| 1419 |
seq_length_with_past = seq_length
|
| 1420 |
past_key_values_length = 0
|
| 1421 |
if past_key_values is not None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1422 |
past_key_values_length = past_key_values.get_seq_length()
|
| 1423 |
seq_length_with_past = seq_length_with_past + past_key_values_length
|
| 1424 |
assert cache_position is None, "cache_position is not supported yet"
|
|
|
|
| 19 |
from torch import nn
|
| 20 |
from torch.nn import functional as F
|
| 21 |
from transformers import PretrainedConfig, PreTrainedModel
|
| 22 |
+
from transformers.cache_utils import DynamicCache
|
| 23 |
from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast
|
| 24 |
|
| 25 |
|
|
|
|
| 328 |
if sequence_length is not None
|
| 329 |
else layer_cache.key.shape[2]
|
| 330 |
)
|
| 331 |
+
if sequence_length is None:
|
| 332 |
+
return 0
|
| 333 |
return sequence_length
|
| 334 |
|
| 335 |
def get_max_length(self) -> int | None:
|
|
|
|
| 1389 |
input_ids: Optional[torch.LongTensor] = None,
|
| 1390 |
attention_mask: Optional[torch.Tensor] = None,
|
| 1391 |
position_ids: Optional[torch.Tensor] = None,
|
| 1392 |
+
past_key_values: Optional[Plamo2Cache | DynamicCache] = None,
|
| 1393 |
inputs_embeds: Optional[torch.Tensor] = None,
|
| 1394 |
image_features: Optional[torch.Tensor] = None,
|
| 1395 |
use_cache: Optional[bool] = None,
|
|
|
|
| 1421 |
seq_length_with_past = seq_length
|
| 1422 |
past_key_values_length = 0
|
| 1423 |
if past_key_values is not None:
|
| 1424 |
+
# In some `transformers` versions, `past_key_values` may be a `DynamicCache` object.
|
| 1425 |
+
if not isinstance(past_key_values, Plamo2Cache):
|
| 1426 |
+
past_key_values_prev = past_key_values
|
| 1427 |
+
past_key_values = Plamo2Cache(self.config)
|
| 1428 |
+
for layer_idx in range(len(past_key_values_prev)):
|
| 1429 |
+
assert isinstance(past_key_values_prev.key_cache[layer_idx], torch.Tensor)
|
| 1430 |
+
past_key_values.update(
|
| 1431 |
+
past_key_values_prev.key_cache[layer_idx],
|
| 1432 |
+
past_key_values_prev.value_cache[layer_idx],
|
| 1433 |
+
layer_idx=layer_idx,
|
| 1434 |
+
)
|
| 1435 |
+
assert isinstance(past_key_values, Plamo2Cache)
|
| 1436 |
past_key_values_length = past_key_values.get_seq_length()
|
| 1437 |
seq_length_with_past = seq_length_with_past + past_key_values_length
|
| 1438 |
assert cache_position is None, "cache_position is not supported yet"
|