Skip to content

Commit

Permalink
Update test to validate response format
Browse files Browse the repository at this point in the history
  • Loading branch information
debermudez committed Aug 8, 2024
1 parent bffd00a commit 6a7820c
Showing 1 changed file with 17 additions and 48 deletions.
65 changes: 17 additions & 48 deletions genai-perf/tests/test_llm_profile_data_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,14 +517,27 @@ def test_empty_response(self, mock_read_write: pytest.MonkeyPatch) -> None:

def test_unfinished_responses(self, mock_read_write: pytest.MonkeyPatch) -> None:
"""Check if it handles unfinished responses."""
tokenizer = get_tokenizer(DEFAULT_TOKENIZER)
res_timestamps = [0, 1, 2]
res_outputs = [
{
"response": 'data: {"id":"8ae835f2ecbb67f3-SJC","object":"chat.completion.chunk","created":1722875835,"choices":[{"index":0,"text"'
},
{
"response": ':" writing","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":4477,"role":"assistant","content":" writing","tool_calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}'
},
{"response": "data: [DONE]\n\n"},
]
expected_response = 'data: {"id":"8ae835f2ecbb67f3-SJC","object":"chat.completion.chunk","created":1722875835,"choices":[{"index":0,"text":" writing","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":4477,"role":"assistant","content":" writing","tool_calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}'

# Should not throw error
_ = LLMProfileDataParser(
filename=Path("unfinished_responses_profile_export.json"),
tokenizer = get_tokenizer(DEFAULT_TOKENIZER)
pd = LLMProfileDataParser(
filename=Path("openai_profile_export.json"),
tokenizer=tokenizer,
)

pd._preprocess_response(res_timestamps, res_outputs)
assert res_outputs[0]["response"] == expected_response

empty_profile_data = {
"service_kind": "openai",
"endpoint": "v1/chat/completions",
Expand Down Expand Up @@ -753,47 +766,3 @@ def test_unfinished_responses(self, mock_read_write: pytest.MonkeyPatch) -> None
},
],
}

# This is a snippet of real data. It is longer than our usual test data.
unfinished_responses_profile_data = {
"service_kind": "openai",
"endpoint": "v1/chat/completions",
"experiments": [
{
"experiment": {
"mode": "concurrency",
"value": 10,
},
"requests": [
{
"timestamp": 1,
"request_inputs": {
"payload": '{"messages":[{"role":"user","content":"This is test"}],"model":"llama-2-7b","stream":true}',
},
"response_timestamps": [3, 5, 8, 12, 13, 14, 16],
"response_outputs": [
{
"response": 'data: {"id":"8ae","object":"chat.completion.chunk","created":172,"choices":[{"index":0,"text":" seems","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":5084,"role":"assistant","content":" seems","tool_calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}\n\ndata: {"id":"8ae835f2ecbb67f3-SJC","object":"chat.completion.chunk","created":1722875835,"choices":[{"index":0,"text":" like","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":1093,"role":"assistant","content":" like","tool_calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}\n\ndata: {"id":"8ae835f2ecbb67f3-SJC","object":"chat.completion.chunk","created":1722875835,"choices":[{"index":0,"text":" you","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":499,"role":"assistant","content":" you","tool_calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}\n\ndata: {"id":"8ae835f2ecbb67f3-SJC","object":"chat.completion.chunk","created":1722875835,"choices":[{"index":0,"text":"\'re","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":2351,"role":"assistant","content":"\'re","tool_calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}\n\ndata: {"id":"8ae835f2ecbb67f3-SJC","object":"chat.completion.chunk","created":1722875835,"choices":[{"index":0,"text"'
},
{
"response": ':" writing","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":4477,"role":"assistant","content":" writing","tool_calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}\n\ndata: {"id":"8ae835f2ecbb67f3-SJC","object":"chat.completion.chunk","created":1722875835,"choices":[{"index":0,"text":" a","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":264,"role":"assistant","content":" a","tool_calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}\n\ndata: {"id":"8ae835f2ecbb67f3-SJC","object":"chat.completion.chunk","created":1722875835,"choices":[{"index":0,"text":" letter","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":6661,"role":"assistant","content":" letter","tool_calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}\n\ndata: {"id":"8ae835f2ecbb67f3-SJC","object":"chat.completion.chunk","created":1722875835,"choices":[{"index":0,"text":" or","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":477,"role":"assistant","content":" or","tool_calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}\n\ndata: {"id":"8ae835f2ecbb67f3-SJC","object":"chat.completion.chunk","created":1722875835,"choices":[{"index":0,"text":" a","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":264,"role":"assistant","content":" a","tool_'
},
{
"response": 'calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}\n\ndata: {"id":"8ae835f2ecbb67f3-SJC","object":"chat.completion.chunk","created":1722875835,"choices":[{"index":0,"text":" passage","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":21765,"role":"assistant","content":" passage","tool_calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}\n\ndata: {"id":"8ae835f2ecbb67f3-SJC","object":"chat.completion.chunk","created":1722875835,"choices":[{"index":0,"text":" with","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":449,"role":"assistant","content":" with","tool_calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}\n\n'
},
{
"response": 'data: {"id":"8ae835f2ecbb67f3-SJC","object":"chat.completion.chunk","created":1722875835,"choices":[{"index":0,"text":" a","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":264,"role":"assistant","content":" a","tool_calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}\n\ndata: {"id":"8ae835f2ecbb67f3-SJC","object":"chat.completion.chunk","created":1722875835,"choices":[{"index":0,"text":" formal","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":16287,"role":"assistant","content":" formal","tool_calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}\n\ndata: {"id":"8ae835f2ecbb67f3-SJC","object":"chat.completion.chunk","created":1722875835,"choices":[{"index":0,"text":" tone","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":16630,"role":"assistant","content":" tone","tool_calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}\n\ndata: {"id":"8ae835f2ecbb67f3-SJC","object":"chat.completion.chunk","created":1722875835,"choices":[{"index":0,"text":",","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":11,"role":"assistant","content":",","tool_calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}\n\ndata: {"id":"8ae835f2ecbb67f3-SJC","object":"chat.completion.chunk","created":1722875835,"choices":[{"index":0,"text":" pos'
},
{
"response": 'sibly","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":11000,"role":"assistant","content":" possibly","tool_calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}\n\ndata: {"id":"8ae835f2ecbb67f3-SJC","object":"chat.completion.chunk","created":1722875835,"choices":[{"index":0,"text":" from","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":505,"role":"assistant","content":" from","tool_calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}\n\ndata: {"id":"8ae835f2ecbb67f3-SJC","object":"chat.completion.chunk","created":1722875835,"choices":[{"index":0,"text":" a","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":264,"role":"assistant","content":" a","tool_calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}\n\ndata: {"id":"8ae835f2ecbb67f3-SJC","object":"chat.completion.chunk","created":1722875835,"choices":[{"index":0,"text":" historical","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":13970,"role":"assistant","content":" historical","tool_calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}\n\ndata: {"id":"8ae835f2ecbb67f3-SJC","object":"chat.completion.chunk","created":1722875835,"choices":[{"index":0,"text":" or","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":477,"role":"assistant","content":'
},
{
"response": '" or","tool_calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}\n\ndata: {"id":"8ae835f2ecbb67f3-SJC","object":"chat.completion.chunk","created":1722875835,"choices":[{"index":0,"text":" literary","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":32465,"role":"assistant","content":" literary","tool_calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}\n\ndata: {"id":"8ae835f2ecbb67f3-SJC","object":"chat.completion.chunk","created":1722875835,"choices":[{"index":0,"text":" context","logprobs":null,"finish_reason":null,"seed":null,"delta":{"token_id":2317,"role":"assistant","content":" context","tool_calls":null}}],"model":"meta-llama/Llama-3-8b-chat-hf","usage":null}\n\n'
},
{"response": "data: [DONE]\n\n"},
],
},
],
},
],
}

0 comments on commit 6a7820c

Please sign in to comment.