-
Notifications
You must be signed in to change notification settings - Fork 4
Feat/attafosu/sglang OpenAI api compatibility #156
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
Changes from all commits
f79e2db
d909fac
2c32417
b04d7d3
4dd91ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,6 +133,7 @@ def __init__( | |
| prompt_column: str = "prompt", | ||
| tokenized_column: str = "input_tokens", | ||
| harmonized_column: str | None = "harmonized_prompt", | ||
| mode: str = "harmony", | ||
| ): | ||
| """Initialize the Harmonize transform. | ||
|
|
||
|
|
@@ -145,10 +146,14 @@ def __init__( | |
| tokenized_column: The name of the column containing the tokenized prompt. | ||
| harmonized_column: The name of the column containing the harmonized prompt. If None, | ||
| the harmonized prompt will not be stored as text. | ||
| mode: "harmony" to render a Harmony conversation; "plain" to tokenize the raw prompt. | ||
| """ | ||
| self.prompt_column = prompt_column | ||
| self.tokenized_column = tokenized_column | ||
| self.harmonized_column = harmonized_column | ||
| self.mode = mode | ||
| if self.mode not in {"harmony", "plain"}: | ||
| raise ValueError(f"Invalid harmonize mode: {self.mode}") | ||
|
Comment on lines
+154
to
+156
|
||
| self.harmonizer = Harmonizer( | ||
| tokenizer_name=tokenizer_name, | ||
| encoding_name=encoding_name, | ||
|
Comment on lines
157
to
159
|
||
|
|
@@ -171,7 +176,19 @@ def process_row(self, row: dict[str, Any]) -> dict[str, Any]: | |
| Returns: | ||
| Row dictionary with the harmonized prompt added | ||
| """ | ||
| row[self.tokenized_column] = self.harmonizer(row[self.prompt_column]) | ||
| # Guard pre-tokenized rows: the SGLang adapter adds a default Harmonize | ||
| # (GPT-OSS tokenizer + harmony mode). When row processors are fused, the | ||
| # dataframe-level skip is bypassed, so without this guard, adapter | ||
| # Harmonize would overwrite input tokens. Alternative: remove Harmonize | ||
| # from the adapter transforms and require each SGLang preset to add its | ||
| # own Harmonize with the desired tokenizer/args. | ||
| if self.tokenized_column in row and row[self.tokenized_column] is not None: | ||
| return row | ||
|
Comment on lines
+185
to
+186
|
||
| if self.mode == "plain": | ||
| tokens = self.harmonizer.to_tokens(row[self.prompt_column]) | ||
| row[self.tokenized_column] = tokens | ||
| else: | ||
| row[self.tokenized_column] = self.harmonizer(row[self.prompt_column]) | ||
|
Comment on lines
176
to
+191
|
||
| if self.harmonized_column is not None: | ||
| row[self.harmonized_column] = self.harmonizer.to_text( | ||
| row[self.tokenized_column] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,7 +82,7 @@ class ChatCompletionResponseMessage(msgspec.Struct, kw_only=True, omit_defaults= | |
|
|
||
| role: str | ||
| content: str | None | ||
| refusal: str | None | ||
| refusal: str | None = None | ||
|
|
||
|
|
||
| class ChatCompletionChoice(msgspec.Struct, kw_only=True, omit_defaults=True): # type: ignore[call-arg] | ||
|
|
@@ -109,5 +109,5 @@ class ChatCompletionResponse(msgspec.Struct, kw_only=True, omit_defaults=True): | |
| created: int | ||
| model: str | ||
| choices: list[ChatCompletionChoice] | ||
| usage: CompletionUsage | None | ||
| system_fingerprint: str | None | ||
| usage: CompletionUsage | None = None | ||
| system_fingerprint: str | None = None | ||
|
Comment on lines
83
to
+113
|
||
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.
The parameters
stream,temperature,top_p, andtop_kare defined in thellama3_8b_sglangfunction signature but are not used within the function body. This indicates dead code, which can be misleading and suggests that these parameters might be intended for future use or were overlooked. If these parameters are not meant to be used, they should be removed. If they are intended to be used, their functionality should be implemented.