Text Generation
Transformers
PyTorch
English
gpt_neox
gpt
llm
large language model
PAIX.Cloud
text-generation-inference
Instructions to use PAIXAI/Astrid-1B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use PAIXAI/Astrid-1B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="PAIXAI/Astrid-1B")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("PAIXAI/Astrid-1B") model = AutoModelForCausalLM.from_pretrained("PAIXAI/Astrid-1B") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use PAIXAI/Astrid-1B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "PAIXAI/Astrid-1B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "PAIXAI/Astrid-1B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/PAIXAI/Astrid-1B
- SGLang
How to use PAIXAI/Astrid-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 "PAIXAI/Astrid-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": "PAIXAI/Astrid-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 "PAIXAI/Astrid-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": "PAIXAI/Astrid-1B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use PAIXAI/Astrid-1B with Docker Model Runner:
docker model run hf.co/PAIXAI/Astrid-1B
Upload h2oai_pipeline.py
Browse files- h2oai_pipeline.py +42 -0
h2oai_pipeline.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import TextGenerationPipeline
|
| 2 |
+
from transformers.pipelines.text_generation import ReturnType
|
| 3 |
+
|
| 4 |
+
STYLE = "<|prompt|>{instruction}<|endoftext|><|answer|>"
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class H2OTextGenerationPipeline(TextGenerationPipeline):
|
| 8 |
+
def __init__(self, *args, **kwargs):
|
| 9 |
+
super().__init__(*args, **kwargs)
|
| 10 |
+
self.prompt = STYLE
|
| 11 |
+
|
| 12 |
+
def preprocess(
|
| 13 |
+
self, prompt_text, prefix="", handle_long_generation=None, **generate_kwargs
|
| 14 |
+
):
|
| 15 |
+
prompt_text = self.prompt.format(instruction=prompt_text)
|
| 16 |
+
return super().preprocess(
|
| 17 |
+
prompt_text,
|
| 18 |
+
prefix=prefix,
|
| 19 |
+
handle_long_generation=handle_long_generation,
|
| 20 |
+
**generate_kwargs,
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
def postprocess(
|
| 24 |
+
self,
|
| 25 |
+
model_outputs,
|
| 26 |
+
return_type=ReturnType.FULL_TEXT,
|
| 27 |
+
clean_up_tokenization_spaces=True,
|
| 28 |
+
):
|
| 29 |
+
records = super().postprocess(
|
| 30 |
+
model_outputs,
|
| 31 |
+
return_type=return_type,
|
| 32 |
+
clean_up_tokenization_spaces=clean_up_tokenization_spaces,
|
| 33 |
+
)
|
| 34 |
+
for rec in records:
|
| 35 |
+
rec["generated_text"] = (
|
| 36 |
+
rec["generated_text"]
|
| 37 |
+
.split("<|answer|>")[1]
|
| 38 |
+
.strip()
|
| 39 |
+
.split("<|prompt|>")[0]
|
| 40 |
+
.strip()
|
| 41 |
+
)
|
| 42 |
+
return records
|