-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Handle concurrent grammar requests #1610
Merged
Merged
Conversation
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
script used during dev import json
import time
import random
import requests
import sys
from concurrent.futures import ThreadPoolExecutor
## read arguments (number of requests to fire)
n = 1
if len(sys.argv) > 1:
n = int(sys.argv[1])
print("Firing", n, "requests...")
# build the request
json_schema = {
"properties": {
"choose_color": {
"description": "Choose a color",
"examples": ["red", "green", "blue"],
"title": "Choose a color",
"type": "string",
}
},
"required": ["choose_color"],
}
def get_input():
return random.choice(
[
"the sky",
"the grass",
"the sea",
"the sun",
"fire",
"a tomato",
"a strawberry",
"a blueberry",
]
)
# prepare function to fire requests
def fire_request():
try:
data = {
"inputs": f"What color is {get_input()}?",
"parameters": {
"best_of": None,
"temperature": 0.3,
"repetition_penalty": 1.1,
"frequency_penalty": None,
"top_k": 30,
"top_p": 0.95,
"typical_p": 0.95,
"do_sample": True,
"max_new_tokens": 30,
"return_full_text": False,
"stop": [],
"truncate": None,
"watermark": False,
"details": True,
"decoder_input_details": False,
"seed": None,
"top_n_tokens": None,
"grammar": {"type": "json", "value": json_schema},
},
}
headers = {
"Content-Type": "application/json",
}
response = requests.post(
"http://127.0.0.1:3000/generate", headers=headers, json=data
)
# print(response.text)
response_data = response.json()
grammar_response = json.loads(response_data["generated_text"])
print(json.dumps(grammar_response, indent=2))
except Exception as e:
# expect that some requests will fail
print(e, response.text)
## fire N requests in parallel
start = time.time()
with ThreadPoolExecutor() as executor:
for _ in range(n):
executor.submit(fire_request)
end = time.time()
print("Time taken:", end - start) run the following to send 10 requests at the same time python concurrent.py 10 |
@drbh you can use k6 for this kind of stuff. You have some template load testing scripts in |
OlivierDehaene
approved these changes
Feb 29, 2024
4 tasks
kdamaszk
pushed a commit
to kdamaszk/tgi-gaudi
that referenced
this pull request
Apr 29, 2024
This PR fixes parallel grammar requests, currently grammar states are not concatenated correctly when a new request is added to the batch and this results in incorrect generation. This PR updates the `concatenate` function to correctly include the previous states. fixes: huggingface#1601
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes parallel grammar requests, currently grammar states are not concatenated correctly when a new request is added to the batch and this results in incorrect generation. This PR updates the
concatenate
function to correctly include the previous states.fixes: #1601