chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
# __sglang_batch_start__
|
||||
import ray
|
||||
from ray.data.llm import SGLangEngineProcessorConfig, build_processor
|
||||
|
||||
config = SGLangEngineProcessorConfig(
|
||||
model_source="unsloth/Llama-3.1-8B-Instruct",
|
||||
engine_kwargs=dict(
|
||||
dtype="half",
|
||||
mem_fraction_static=0.8,
|
||||
),
|
||||
batch_size=32,
|
||||
concurrency=1,
|
||||
)
|
||||
|
||||
processor = build_processor(
|
||||
config,
|
||||
preprocess=lambda row: dict(
|
||||
messages=[
|
||||
{"role": "system", "content": "You are a helpful assistant."},
|
||||
{"role": "user", "content": row["prompt"]},
|
||||
],
|
||||
sampling_params=dict(
|
||||
temperature=0.7,
|
||||
max_new_tokens=256,
|
||||
),
|
||||
),
|
||||
postprocess=lambda row: dict(
|
||||
prompt=row["prompt"],
|
||||
response=row["generated_text"],
|
||||
),
|
||||
)
|
||||
|
||||
ds = ray.data.from_items(
|
||||
[
|
||||
{"prompt": "What is the capital of France?"},
|
||||
{"prompt": "Explain photosynthesis in one sentence."},
|
||||
{"prompt": "Write a haiku about programming."},
|
||||
]
|
||||
)
|
||||
ds = processor(ds)
|
||||
|
||||
for row in ds.take_all():
|
||||
print(f"Prompt: {row['prompt']}")
|
||||
print(f"Response: {row['response']}\n")
|
||||
# __sglang_batch_end__
|
||||
@@ -0,0 +1,36 @@
|
||||
# __sglang_multinode_start__
|
||||
from ray.llm._internal.serve.engines.sglang import SGLangServer
|
||||
|
||||
from ray import serve
|
||||
from ray.serve.llm import LLMConfig, build_openai_app
|
||||
|
||||
llm_config = LLMConfig(
|
||||
model_loading_config={
|
||||
"model_id": "Llama-3.1-70B-Instruct",
|
||||
"model_source": "meta-llama/Llama-3.1-70B-Instruct",
|
||||
},
|
||||
deployment_config={
|
||||
"autoscaling_config": {
|
||||
"min_replicas": 1,
|
||||
"max_replicas": 2,
|
||||
"target_ongoing_requests": 4,
|
||||
}
|
||||
},
|
||||
# PACK fills GPUs on each node before moving to the next.
|
||||
# With 8 bundles across 2 nodes (4 GPUs each), each node gets 4 bundles.
|
||||
placement_group_config={
|
||||
"placement_group_bundles": [{"CPU": 1, "GPU": 1}] + [{"GPU": 1}] * 7,
|
||||
"placement_group_strategy": "PACK",
|
||||
},
|
||||
server_cls=SGLangServer,
|
||||
engine_kwargs={
|
||||
"model_path": "meta-llama/Llama-3.1-70B-Instruct",
|
||||
"tp_size": 4,
|
||||
"pp_size": 2,
|
||||
"mem_fraction_static": 0.8,
|
||||
},
|
||||
)
|
||||
|
||||
app = build_openai_app({"llm_configs": [llm_config]})
|
||||
serve.run(app, blocking=True)
|
||||
# __sglang_multinode_end__
|
||||
@@ -0,0 +1,27 @@
|
||||
# __sglang_query_start__
|
||||
from openai import OpenAI
|
||||
|
||||
client = OpenAI(base_url="http://localhost:8000/v1", api_key="fake-key")
|
||||
|
||||
# Chat completions
|
||||
print("=== Chat Completions ===")
|
||||
chat_response = client.chat.completions.create(
|
||||
model="Llama-3.1-8B-Instruct",
|
||||
messages=[
|
||||
{"role": "user", "content": "List 3 countries and their capitals."},
|
||||
],
|
||||
temperature=0,
|
||||
max_tokens=64,
|
||||
)
|
||||
print(chat_response.choices[0].message.content)
|
||||
|
||||
# Text completions
|
||||
print("\n=== Text Completions ===")
|
||||
completion_response = client.completions.create(
|
||||
model="Llama-3.1-8B-Instruct",
|
||||
prompt="San Francisco is a",
|
||||
temperature=0,
|
||||
max_tokens=30,
|
||||
)
|
||||
print(completion_response.choices[0].text)
|
||||
# __sglang_query_end__
|
||||
@@ -0,0 +1,29 @@
|
||||
# __sglang_single_node_start__
|
||||
from ray.llm._internal.serve.engines.sglang import SGLangServer
|
||||
|
||||
from ray import serve
|
||||
from ray.serve.llm import LLMConfig, build_openai_app
|
||||
|
||||
llm_config = LLMConfig(
|
||||
model_loading_config={
|
||||
"model_id": "Llama-3.1-8B-Instruct",
|
||||
"model_source": "unsloth/Llama-3.1-8B-Instruct",
|
||||
},
|
||||
deployment_config={
|
||||
"autoscaling_config": {
|
||||
"min_replicas": 1,
|
||||
"max_replicas": 2,
|
||||
}
|
||||
},
|
||||
server_cls=SGLangServer,
|
||||
engine_kwargs={
|
||||
"trust_remote_code": True,
|
||||
"model_path": "unsloth/Llama-3.1-8B-Instruct",
|
||||
"tp_size": 1,
|
||||
"mem_fraction_static": 0.8,
|
||||
},
|
||||
)
|
||||
|
||||
app = build_openai_app({"llm_configs": [llm_config]})
|
||||
serve.run(app, blocking=True)
|
||||
# __sglang_single_node_end__
|
||||
Reference in New Issue
Block a user