Skip to content
Merged
Changes from 7 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions python/sglang/bench_offline_throughput.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,22 @@ def throughput_test(
ServerArgs.add_cli_args(parser)
BenchArgs.add_cli_args(parser)
args = parser.parse_args()

# handling Modelscope model downloads
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ModelScope

if os.getenv("SGLANG_USE_MODELSCOPE", "false").lower() in ("true", "1"):
try:
from modelscope import snapshot_download
print(f"Using ModelScope to download model: {args.model_path}")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的args.model_path有可能是模型的本地路径吗?是不是要做个判断?


# download the model and replace args.model_path
args.model_path = snapshot_download(
args.model_path,
)
print(f"Model downloaded to: {args.model_path}")
except Exception as e:
print(f"ModelScope download failed: {str(e)}")
raise e

Comment on lines +421 to +440
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

  • Redundant Import: The import os on line 423 is redundant since os is already imported at the top of the file (line 19).
  • Improved Exception Handling: The exception handling can be more specific. Catch ImportError for optional dependencies like modelscope separately to provide a more helpful error message if the package isn't installed.
    # handling Modelscope model downloads
    if os.getenv("SGLANG_USE_MODELSCOPE", "false").lower() in ("true", "1"):
        try:
            from modelscope import snapshot_download
        except ImportError:
            print(
                "Error: modelscope is not installed. "
                "Please install it via `pip install modelscope` to use this feature."
            )
            raise

        try:
            os.environ["TRANSFORMERS_OFFLINE"] = "1"
            os.environ["HF_DATASETS_OFFLINE"] = "1"
            os.environ["HF_EVALUATE_OFFLINE"] = "1"

            print(f"Using ModelScope to download model: {args.model_path}")

            # download the model and replace args.model_path
            args.model_path = snapshot_download(
                args.model_path,
                cache_dir=os.getenv("MODELSCOPE_CACHE"),
                revision=os.getenv("MODEL_REVISION"),
                local_files_only=False,
            )
            print(f"Model downloaded to: {args.model_path}")

            if hasattr(args, "tokenizer_path") and args.tokenizer_path is None:
                args.tokenizer_path = args.model_path
        except Exception as e:
            print(f"ModelScope download failed: {e}")
            raise

server_args = ServerArgs.from_cli_args(args)
bench_args = BenchArgs.from_cli_args(args)

Expand Down