-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat/1001: sglang integration #1122
Conversation
commit 6c9059f Author: Jayon02 <[email protected]> Date: Thu Feb 27 02:50:07 2025 +0000 add detokenize commit 159f1ef Author: Jayon02 <[email protected]> Date: Tue Feb 25 11:34:05 2025 +0000 support sglang embedding commit f2b2064 Author: Jayon02 <[email protected]> Date: Tue Feb 25 08:06:05 2025 +0000 fix test bugs commit ba3a5a7 Author: Jayon02 <[email protected]> Date: Mon Feb 24 16:55:53 2025 +0000 fix bugs in multiple generations and add test commit f893c6d Author: Jayon02 <[email protected]> Date: Sat Feb 22 17:13:12 2025 +0000 modify function annotation commit ddde5cb Author: Jayon02 <[email protected]> Date: Sat Feb 22 12:06:11 2025 +0000 support structure output and SGLang openai client commit 5ecedc4 Author: Jayon02 <[email protected]> Date: Sat Feb 22 06:22:42 2025 +0000 support sglang
CudaDevicePlacementMixin.load(self) | ||
|
||
try: | ||
from sglang import Engine as _SGLang |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why should use this by the name "_SGLang". COuld we directly use Engine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I align with the format in vllm. Should I reformat what I commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use from sglang import Engine
here, it's fine
|
||
def unload(self) -> None: | ||
"""Unloads the `SGLang` model.""" | ||
self._cleanup_sglang_model() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is the definition of _cleanup_sglang_model()
? Also, do not use _
as this could be a public funciton.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it.
CodSpeed Performance ReportMerging #1122 will improve performances by ×2.1Comparing Summary
Benchmarks breakdown
|
Awesome PR, I've asked @plaguss and @gabrielmbmb to review it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome job! some small comments, and a couple of things to tackle
CudaDevicePlacementMixin.load(self) | ||
|
||
try: | ||
from sglang import Engine as _SGLang |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use from sglang import Engine
here, it's fine
Could you add the required dependencies so that we can run: uv pip install distilabel[sglang] and have it ready? I run the command from the guide and it works: uv pip install "sglang[all]>=0.4.3.post2" --find-links https://flashinfer.ai/whl/cu124/torch2.5/flashinfer-python but should be reflected in the |
Also, the example from the structured outputs is failing: from distilabel.models.llms import SGLang
from pydantic import BaseModel
if __name__ == "__main__":
class User(BaseModel):
name: str
last_name: str
id: int
llm = SGLang(
model="Qwen/Qwen2.5-Coder-3B-Instruct",
structured_output={"format": "json", "schema": User},
)
llm.load()
# Call the model
output = llm.generate_outputs(inputs=[[{"role": "user", "content": "Create a user profile for the following marathon"}]]) It throws the following trace: [2025-02-27 09:04:17 TP0] Scheduler hit an exception: Traceback (most recent call last):
File "/fsx/agustin_piqueres/test-distilabel/.venv/lib/python3.11/site-packages/sglang/srt/managers/scheduler.py", line 1825, in run_scheduler_process
scheduler.event_loop_overlap()
File "/fsx/agustin_piqueres/test-distilabel/.venv/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/fsx/agustin_piqueres/test-distilabel/.venv/lib/python3.11/site-packages/sglang/srt/managers/scheduler.py", line 496, in event_loop_overlap
batch = self.get_next_batch_to_run()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/fsx/agustin_piqueres/test-distilabel/.venv/lib/python3.11/site-packages/sglang/srt/managers/scheduler.py", line 877, in get_next_batch_to_run
new_batch = self.get_new_batch_prefill()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/fsx/agustin_piqueres/test-distilabel/.venv/lib/python3.11/site-packages/sglang/srt/managers/scheduler.py", line 898, in get_new_batch_prefill
self.move_ready_grammar_requests()
File "/fsx/agustin_piqueres/test-distilabel/.venv/lib/python3.11/site-packages/sglang/srt/managers/scheduler.py", line 1594, in move_ready_grammar_requests
req.grammar = req.grammar.result(timeout=0.05)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/admin/home/agustin_piqueres/.pyenv/versions/3.11.9/lib/python3.11/concurrent/futures/_base.py", line 456, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "/admin/home/agustin_piqueres/.pyenv/versions/3.11.9/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
File "/admin/home/agustin_piqueres/.pyenv/versions/3.11.9/lib/python3.11/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/fsx/agustin_piqueres/test-distilabel/.venv/lib/python3.11/site-packages/sglang/srt/constrained/base_grammar_backend.py", line 53, in init_value
entry.value = self.init_value_impl(key)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/fsx/agustin_piqueres/test-distilabel/.venv/lib/python3.11/site-packages/sglang/srt/constrained/outlines_backend.py", line 173, in init_value_impl
guide = RegexGuide.from_regex(regex, self.outlines_tokenizer)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/fsx/agustin_piqueres/test-distilabel/.venv/lib/python3.11/site-packages/outlines/fsm/guide.py", line 92, in from_regex
return super().from_regex(
^^^^^^^^^^^^^^^^^^^
File "/fsx/agustin_piqueres/test-distilabel/.venv/lib/python3.11/site-packages/outlines_core/fsm/guide.py", line 212, in from_regex
) = _create_states_mapping(
^^^^^^^^^^^^^^^^^^^^^^^
File "/fsx/agustin_piqueres/test-distilabel/.venv/lib/python3.11/site-packages/outlines/fsm/guide.py", line 76, in cached_create_states_mapping
return uncached_create_states_mapping(regex_string, tokenizer, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/fsx/agustin_piqueres/test-distilabel/.venv/lib/python3.11/site-packages/outlines_core/fsm/guide.py", line 141, in create_states_mapping
return create_states_mapping_from_fsm(regex_fsm, tokenizer, frozen_tokens)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/fsx/agustin_piqueres/test-distilabel/.venv/lib/python3.11/site-packages/outlines_core/fsm/guide.py", line 178, in create_states_mapping_from_fsm
states_to_token_maps, empty_token_ids = create_fsm_index_tokenizer(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/fsx/agustin_piqueres/test-distilabel/.venv/lib/python3.11/site-packages/outlines_core/fsm/regex.py", line 473, in create_fsm_index_tokenizer
tokens_to_token_ids, empty_token_ids = reduced_vocabulary(tokenizer)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/fsx/agustin_piqueres/test-distilabel/.venv/lib/python3.11/site-packages/outlines/models/transformers.py", line 119, in __hash__
return hash(Hasher.hash(self.tokenizer))
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/fsx/agustin_piqueres/test-distilabel/.venv/lib/python3.11/site-packages/datasets/fingerprint.py", line 188, in hash
return cls.hash_bytes(dumps(value))
^^^^^^^^^^^^
File "/fsx/agustin_piqueres/test-distilabel/.venv/lib/python3.11/site-packages/datasets/utils/_dill.py", line 109, in dumps
dump(obj, file)
File "/fsx/agustin_piqueres/test-distilabel/.venv/lib/python3.11/site-packages/datasets/utils/_dill.py", line 103, in dump
Pickler(file, recurse=True).dump(obj)
File "/fsx/agustin_piqueres/test-distilabel/.venv/lib/python3.11/site-packages/dill/_dill.py", line 428, in dump
StockPickler.dump(self, obj)
File "/admin/home/agustin_piqueres/.pyenv/versions/3.11.9/lib/python3.11/pickle.py", line 487, in dump
self.save(obj)
File "/fsx/agustin_piqueres/test-distilabel/.venv/lib/python3.11/site-packages/datasets/utils/_dill.py", line 70, in save
dill.Pickler.save(self, obj, save_persistent_id=save_persistent_id)
File "/fsx/agustin_piqueres/test-distilabel/.venv/lib/python3.11/site-packages/dill/_dill.py", line 422, in save
StockPickler.save(self, obj, save_persistent_id)
File "/admin/home/agustin_piqueres/.pyenv/versions/3.11.9/lib/python3.11/pickle.py", line 560, in save
f(self, obj) # Call unbound method with explicit self
^^^^^^^^^^^^
File "/fsx/agustin_piqueres/test-distilabel/.venv/lib/python3.11/site-packages/datasets/utils/_dill.py", line 209, in _save_transformersPreTrainedTokenizerBase
log(pickler, f"Tok: {obj}")
^^^
NameError: name 'log' is not defined
[2025-02-27 09:04:17] Received sigquit from a child proces. It usually means the child failed.
Killed |
for the integration test failing, I already fixed in the the |
This issue seems quite strange and I don't find bugs about sglang in this context. In my environment, this code can work correctly. Could you use docker to run the repo? Maybe it can give more useful information and I will fix it. |
Have you run it? if that's the case, it can be just a case of having some of my dependencies outdated, will take a look |
Ok!I will merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just changing the version in the pyproject and should be ready to go
Yes. I have just run it correctly. |
This PR closes #1001.
In this PR, I integrate
sglang
into Distilabel, allowing users to usesglang
as the backend for dataset generation.Tasks
sglang
as a potential backend for data generation. See here.sglang
as a potential backend for embedding generation. See here.Examples
Here are some examples for you to use sglang in distilabel. More detailed documentation will be added.
Please let me know if there is anything that could be improved. Thanks to all SGLang team members for their help.