Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
change
sglang
Commits
eb4308c4
Unverified
Commit
eb4308c4
authored
Mar 12, 2024
by
Arsalan
Committed by
GitHub
Mar 12, 2024
Browse files
adding the triton docker build minimal example (#242)
parent
b2eb0805
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
119 additions
and
0 deletions
+119
-0
examples/usage/triton/Dockerfile
examples/usage/triton/Dockerfile
+10
-0
examples/usage/triton/README.md
examples/usage/triton/README.md
+41
-0
examples/usage/triton/models/character_generation/1/model.py
examples/usage/triton/models/character_generation/1/model.py
+45
-0
examples/usage/triton/models/character_generation/config.pbtxt
...les/usage/triton/models/character_generation/config.pbtxt
+23
-0
No files found.
examples/usage/triton/Dockerfile
0 → 100644
View file @
eb4308c4
FROM
nvcr.io/nvidia/tritonserver:24.01-py3
WORKDIR
/opt
RUN
git clone https://github.com/sgl-project/sglang.git
WORKDIR
/opt/sglang
RUN
pip
install
--upgrade
pip
&&
\
pip
install
-e
"python[all]"
&&
\
pip
install
datasets
\ No newline at end of file
examples/usage/triton/README.md
0 → 100644
View file @
eb4308c4
# sglang_triton
Build the docker image:
```
docker build -t sglang-triton .
```
Then do:
```
docker run -ti --gpus=all --network=host --name sglang-triton -v ./models:/mnt/models sglang-triton
```
inside the docker container:
```
cd sglang
python3 -m sglang.launch_server --model-path mistralai/Mistral-7B-Instruct-v0.2 --port 30000 --mem-fraction-static 0.9
```
with another shell, inside the docker container:
```
docker exec -ti sglang-triton /bin/bash
cd /mnt
tritonserver --model-repository=/mnt/models
```
Send request to the server:
```
curl -X POST http://localhost:8000/v2/models/character_generation/generate \
-H "Content-Type: application/json" \
-d '{
"inputs": [
{
"name": "INPUT_TEXT",
"datatype": "STRING",
"shape": [1],
"data": ["Name1"]
}
]
}'
```
\ No newline at end of file
examples/usage/triton/models/character_generation/1/model.py
0 → 100644
View file @
eb4308c4
import
triton_python_backend_utils
as
pb_utils
import
numpy
import
sglang
as
sgl
from
sglang
import
function
,
set_default_backend
from
sglang.srt.constrained
import
build_regex_from_object
from
pydantic
import
BaseModel
sgl
.
set_default_backend
(
sgl
.
RuntimeEndpoint
(
"http://localhost:30000"
))
class
Character
(
BaseModel
):
name
:
str
eye_color
:
str
house
:
str
@
function
def
character_gen
(
s
,
name
):
s
+=
(
name
+
" is a character in Harry Potter. Please fill in the following information about this character.
\n
"
)
s
+=
sgl
.
gen
(
"json_output"
,
max_tokens
=
256
,
regex
=
build_regex_from_object
(
Character
))
class
TritonPythonModel
:
def
initialize
(
self
,
args
):
print
(
"Initialized."
)
def
execute
(
self
,
requests
):
responses
=
[]
for
request
in
requests
:
tensor_in
=
pb_utils
.
get_input_tensor_by_name
(
request
,
"INPUT_TEXT"
)
if
tensor_in
is
None
:
return
pb_utils
.
InferenceResponse
(
output_tensors
=
[])
input_list_names
=
[
i
.
decode
(
'utf-8'
)
if
isinstance
(
i
,
bytes
)
else
i
for
i
in
tensor_in
.
as_numpy
().
tolist
()]
input_list_dicts
=
[{
"name"
:
i
}
for
i
in
input_list_names
]
states
=
character_gen
.
run_batch
(
input_list_dicts
)
character_strs
=
[
state
.
text
()
for
state
in
states
]
tensor_out
=
pb_utils
.
Tensor
(
"OUTPUT_TEXT"
,
numpy
.
array
(
character_strs
,
dtype
=
object
))
responses
.
append
(
pb_utils
.
InferenceResponse
(
output_tensors
=
[
tensor_out
]))
return
responses
\ No newline at end of file
examples/usage/triton/models/character_generation/config.pbtxt
0 → 100644
View file @
eb4308c4
name: "character_generation"
backend: "python"
input [
{
name: "INPUT_TEXT"
data_type: TYPE_STRING
dims: [ -1 ]
}
]
output [
{
name: "OUTPUT_TEXT"
data_type: TYPE_STRING
dims: [ -1 ]
}
]
instance_group [
{
count: 1
kind: KIND_GPU
gpus: [ 0 ]
}
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment