-
Notifications
You must be signed in to change notification settings - Fork 713
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support speculative execution for openai API (#48)
Co-authored-by: Ying Sheng <sqy1415@gmail.com>
- Loading branch information
1 parent
93414c8
commit 2395005
Showing
10 changed files
with
178 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from sglang import function, gen, set_default_backend, OpenAI | ||
|
||
|
||
@function(api_num_spec_tokens=512) | ||
def gen_character_spec(s): | ||
s += "Construct a character within the following format:\n" | ||
s += "Name: Steve Jobs.\nBirthday: February 24, 1955.\nJob: Apple CEO.\n" | ||
s += "\nPlease generate new Name, Birthday and Job.\n" | ||
s += "Name:" + gen("name", stop="\n") + "\nBirthday:" + gen("birthday", stop="\n") | ||
s += "\nJob:" + gen("job", stop="\n") + "\n" | ||
|
||
|
||
set_default_backend(OpenAI("gpt-3.5-turbo-instruct")) | ||
|
||
state = gen_character_spec.run() | ||
|
||
print("name:", state["name"]) | ||
print("birthday:", state["birthday"]) | ||
print("job:", state["job"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from sglang import OpenAI, function, gen, set_default_backend | ||
|
||
|
||
@function() | ||
def gen_character_default(s): | ||
s += "Construct a character within the following format:\n" | ||
s += "Name: Steve Jobs.\nBirthday: February 24, 1955.\nJob: Apple CEO.\nWelcome.\n" | ||
s += "\nPlease generate new Name, Birthday and Job.\n" | ||
s += "Name:" + gen("name", stop="\n") + "\nBirthday:" + gen("birthday", stop="\n") | ||
s += "\nJob:" + gen("job", stop="\n") + "\nWelcome.\n" | ||
|
||
|
||
@function(api_num_spec_tokens=512) | ||
def gen_character_spec(s): | ||
s += "Construct a character within the following format:\n" | ||
s += "Name: Steve Jobs.\nBirthday: February 24, 1955.\nJob: Apple CEO.\nWelcome.\n" | ||
s += "\nPlease generate new Name, Birthday and Job.\n" | ||
s += "Name:" + gen("name", stop="\n") + "\nBirthday:" + gen("birthday", stop="\n") | ||
s += "\nJob:" + gen("job", stop="\n") + "\nWelcome.\n" | ||
|
||
|
||
@function(api_num_spec_tokens=512) | ||
def gen_character_no_stop(s): | ||
s += "Construct a character within the following format:\n" | ||
s += "Name: Steve Jobs.\nBirthday: February 24, 1955.\nJob: Apple CEO.\nWelcome.\n" | ||
s += "\nPlease generate new Name, Birthday and Job.\n" | ||
s += "Name:" + gen("name") + "\nBirthday:" + gen("birthday") | ||
s += "\nJob:" + gen("job") + "\nWelcome.\n" | ||
|
||
|
||
@function(api_num_spec_tokens=512) | ||
def gen_character_multi_stop(s): | ||
s += "Construct a character within the following format:\n" | ||
s += ( | ||
"Name: Steve Jobs.###Birthday: February 24, 1955.###Job: Apple CEO.\nWelcome.\n" | ||
) | ||
s += "\nPlease generate new Name, Birthday and Job.\n" | ||
s += "Name:" + gen("name", stop=["\n", "###"]) | ||
s += "###Birthday:" + gen("birthday", stop=["\n", "###"]) | ||
s += "###Job:" + gen("job", stop=["\n", "###"]) + "\nWelcome.\n" | ||
|
||
|
||
set_default_backend(OpenAI("gpt-3.5-turbo-instruct")) | ||
|
||
state = gen_character_default.run() | ||
print(state.text()) | ||
|
||
print("=" * 60) | ||
|
||
state = gen_character_no_stop.run() | ||
|
||
print("name###", state["name"]) | ||
print("birthday###:", state["birthday"]) | ||
print("job###", state["job"]) | ||
|
||
print("=" * 60) | ||
|
||
state = gen_character_multi_stop.run() | ||
print(state.text()) | ||
|
||
print("=" * 60) | ||
|
||
state = gen_character_spec.run() | ||
print(state.text()) | ||
|
||
print("name###", state["name"]) | ||
print("birthday###", state["birthday"]) | ||
print("job###", state["job"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters