Skip to content

Commit

Permalink
use jsonlines library
Browse files Browse the repository at this point in the history
- simpler code
  • Loading branch information
min-xu-et committed Aug 4, 2024
1 parent f52110d commit bcfafd3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies = [

[project.optional-dependencies]
srt = ["aiohttp", "fastapi", "hf_transfer", "huggingface_hub", "interegular", "packaging", "pillow",
"psutil", "pydantic", "torch", "uvicorn", "uvloop", "zmq", "vllm==0.5.3.post1", "outlines>=0.0.44", "python-multipart"]
"psutil", "pydantic", "torch", "uvicorn", "uvloop", "zmq", "vllm==0.5.3.post1", "outlines>=0.0.44", "python-multipart", "jsonlines"]
openai = ["openai>=1.0", "tiktoken"]
anthropic = ["anthropic>=0.20.0"]
litellm = ["litellm>=1.0.0"]
Expand Down
14 changes: 4 additions & 10 deletions python/sglang/bench_latency.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@

import argparse
import dataclasses
import json
import logging
import multiprocessing
import os
import time
from typing import Tuple

import jsonlines
import numpy as np
import torch
import torch.distributed as dist
Expand Down Expand Up @@ -309,15 +308,10 @@ def run_once(output_len):
result_list = []
result_list.append(run_once(bench_args.output_len))

# Write results in jsonl
# Write results in jsonlines format.
if bench_args.result_filename:
open_mode = "w"
if os.path.isfile(bench_args.result_filename):
open_mode = "a"
with open(bench_args.result_filename, open_mode) as f:
for ret in result_list:
json.dump(ret, f)
f.write("\n")
with jsonlines.open(bench_args.result_filename, "a") as f:
f.write_all(result_list)


def main(server_args, bench_args):
Expand Down

0 comments on commit bcfafd3

Please sign in to comment.