Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
3a63be0f
Unverified
Commit
3a63be0f
authored
Jan 22, 2026
by
David Ramon Prados
Committed by
GitHub
Jan 22, 2026
Browse files
Support custom URI schemes and trace handlers for profiler (#32393)
parent
803e3f3f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
19 deletions
+74
-19
tests/v1/worker/test_gpu_profiler.py
tests/v1/worker/test_gpu_profiler.py
+34
-0
vllm/config/profiler.py
vllm/config/profiler.py
+19
-11
vllm/profiler/wrapper.py
vllm/profiler/wrapper.py
+21
-8
No files found.
tests/v1/worker/test_gpu_profiler.py
View file @
3a63be0f
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
import
pytest
import
pytest
from
vllm.config
import
ProfilerConfig
from
vllm.config
import
ProfilerConfig
from
vllm.config.profiler
import
_is_uri_path
from
vllm.profiler.wrapper
import
WorkerProfiler
from
vllm.profiler.wrapper
import
WorkerProfiler
...
@@ -202,3 +203,36 @@ def test_mixed_delay_and_stop(default_profiler_config):
...
@@ -202,3 +203,36 @@ def test_mixed_delay_and_stop(default_profiler_config):
profiler
.
step
()
profiler
.
step
()
assert
profiler
.
start_call_count
==
0
assert
profiler
.
start_call_count
==
0
class
TestIsUriPath
:
"""Tests for the _is_uri_path helper function."""
@
pytest
.
mark
.
parametrize
(
"path,expected"
,
[
# Valid URI schemes - should return True
(
"gs://bucket/path"
,
True
),
(
"s3://bucket/path"
,
True
),
(
"hdfs://cluster/path"
,
True
),
(
"abfs://container/path"
,
True
),
(
"http://example.com/path"
,
True
),
(
"https://example.com/path"
,
True
),
# Local paths - should return False
(
"/tmp/local/path"
,
False
),
(
"./relative/path"
,
False
),
(
"relative/path"
,
False
),
(
"/absolute/path"
,
False
),
# Windows drive letters - should return False (single char scheme)
(
"C://windows/path"
,
False
),
(
"D://drive/path"
,
False
),
# Edge cases
(
""
,
False
),
(
"no-scheme"
,
False
),
(
"scheme-no-slashes:"
,
False
),
(
"://no-scheme"
,
False
),
],
)
def
test_is_uri_path
(
self
,
path
,
expected
):
"""Test that _is_uri_path correctly identifies URI vs local paths."""
assert
_is_uri_path
(
path
)
==
expected
vllm/config/profiler.py
View file @
3a63be0f
...
@@ -18,6 +18,20 @@ logger = init_logger(__name__)
...
@@ -18,6 +18,20 @@ logger = init_logger(__name__)
ProfilerKind
=
Literal
[
"torch"
,
"cuda"
]
ProfilerKind
=
Literal
[
"torch"
,
"cuda"
]
def
_is_uri_path
(
path
:
str
)
->
bool
:
"""Check if path is a URI (scheme://...), excluding Windows drive letters.
Supports custom URI schemes like gs://, s3://, hdfs://, etc.
These paths should not be converted to absolute paths.
"""
if
"://"
in
path
:
scheme
=
path
.
split
(
"://"
)[
0
]
# Windows drive letters are single characters (e.g., C://)
# Valid URI schemes have more than one character
return
len
(
scheme
)
>
1
return
False
@
config
@
config
@
dataclass
@
dataclass
class
ProfilerConfig
:
class
ProfilerConfig
:
...
@@ -185,15 +199,9 @@ class ProfilerConfig:
...
@@ -185,15 +199,9 @@ class ProfilerConfig:
if
self
.
profiler
==
"torch"
and
not
profiler_dir
:
if
self
.
profiler
==
"torch"
and
not
profiler_dir
:
raise
ValueError
(
"torch_profiler_dir must be set when profiler is 'torch'"
)
raise
ValueError
(
"torch_profiler_dir must be set when profiler is 'torch'"
)
if
profiler_dir
:
# Support any URI scheme (gs://, s3://, hdfs://, etc.)
is_gs_path
=
(
# These paths should not be converted to absolute paths
profiler_dir
.
startswith
(
"gs://"
)
if
profiler_dir
and
not
_is_uri_path
(
profiler_dir
):
and
profiler_dir
[
5
:]
self
.
torch_profiler_dir
=
os
.
path
.
abspath
(
os
.
path
.
expanduser
(
profiler_dir
))
and
profiler_dir
[
5
]
!=
"/"
)
if
not
is_gs_path
:
self
.
torch_profiler_dir
=
os
.
path
.
abspath
(
os
.
path
.
expanduser
(
profiler_dir
)
)
return
self
return
self
vllm/profiler/wrapper.py
View file @
3a63be0f
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from
abc
import
ABC
,
abstractmethod
from
abc
import
ABC
,
abstractmethod
from
collections.abc
import
Callable
from
contextlib
import
nullcontext
from
contextlib
import
nullcontext
from
typing
import
Literal
from
typing
import
Literal
...
@@ -9,6 +10,7 @@ import torch
...
@@ -9,6 +10,7 @@ import torch
from
typing_extensions
import
override
from
typing_extensions
import
override
from
vllm.config
import
ProfilerConfig
from
vllm.config
import
ProfilerConfig
from
vllm.config.profiler
import
_is_uri_path
from
vllm.logger
import
init_logger
from
vllm.logger
import
init_logger
logger
=
init_logger
(
__name__
)
logger
=
init_logger
(
__name__
)
...
@@ -151,6 +153,7 @@ class TorchProfilerWrapper(WorkerProfiler):
...
@@ -151,6 +153,7 @@ class TorchProfilerWrapper(WorkerProfiler):
worker_name
:
str
,
worker_name
:
str
,
local_rank
:
int
,
local_rank
:
int
,
activities
:
list
[
TorchProfilerActivity
],
activities
:
list
[
TorchProfilerActivity
],
on_trace_ready
:
Callable
[[
torch
.
profiler
.
profile
],
None
]
|
None
=
None
,
)
->
None
:
)
->
None
:
super
().
__init__
(
profiler_config
)
super
().
__init__
(
profiler_config
)
...
@@ -172,6 +175,17 @@ class TorchProfilerWrapper(WorkerProfiler):
...
@@ -172,6 +175,17 @@ class TorchProfilerWrapper(WorkerProfiler):
profiler_config
.
torch_profiler_with_flops
,
profiler_config
.
torch_profiler_with_flops
,
)
)
# Determine trace handler: use custom handler if provided,
# otherwise default to tensorboard trace handler
if
on_trace_ready
is
not
None
:
trace_handler
=
on_trace_ready
else
:
trace_handler
=
torch
.
profiler
.
tensorboard_trace_handler
(
torch_profiler_trace_dir
,
worker_name
=
worker_name
,
use_gzip
=
profiler_config
.
torch_profiler_use_gzip
,
)
self
.
dump_cpu_time_total
=
"CPU"
in
activities
and
len
(
activities
)
==
1
self
.
dump_cpu_time_total
=
"CPU"
in
activities
and
len
(
activities
)
==
1
self
.
profiler
=
torch
.
profiler
.
profile
(
self
.
profiler
=
torch
.
profiler
.
profile
(
activities
=
[
TorchProfilerActivityMap
[
activity
]
for
activity
in
activities
],
activities
=
[
TorchProfilerActivityMap
[
activity
]
for
activity
in
activities
],
...
@@ -179,11 +193,7 @@ class TorchProfilerWrapper(WorkerProfiler):
...
@@ -179,11 +193,7 @@ class TorchProfilerWrapper(WorkerProfiler):
profile_memory
=
profiler_config
.
torch_profiler_with_memory
,
profile_memory
=
profiler_config
.
torch_profiler_with_memory
,
with_stack
=
profiler_config
.
torch_profiler_with_stack
,
with_stack
=
profiler_config
.
torch_profiler_with_stack
,
with_flops
=
profiler_config
.
torch_profiler_with_flops
,
with_flops
=
profiler_config
.
torch_profiler_with_flops
,
on_trace_ready
=
torch
.
profiler
.
tensorboard_trace_handler
(
on_trace_ready
=
trace_handler
,
torch_profiler_trace_dir
,
worker_name
=
worker_name
,
use_gzip
=
profiler_config
.
torch_profiler_use_gzip
,
),
)
)
@
override
@
override
...
@@ -198,10 +208,13 @@ class TorchProfilerWrapper(WorkerProfiler):
...
@@ -198,10 +208,13 @@ class TorchProfilerWrapper(WorkerProfiler):
rank
=
self
.
local_rank
rank
=
self
.
local_rank
if
profiler_config
.
torch_profiler_dump_cuda_time_total
:
if
profiler_config
.
torch_profiler_dump_cuda_time_total
:
profiler_dir
=
profiler_config
.
torch_profiler_dir
profiler_dir
=
profiler_config
.
torch_profiler_dir
profiler_out_file
=
f
"
{
profiler_dir
}
/profiler_out_
{
rank
}
.txt"
sort_key
=
"self_cuda_time_total"
sort_key
=
"self_cuda_time_total"
table
=
self
.
profiler
.
key_averages
().
table
(
sort_by
=
sort_key
)
table
=
self
.
profiler
.
key_averages
().
table
(
sort_by
=
sort_key
)
# Skip file write for URI paths (gs://, s3://, etc.)
# as standard file I/O doesn't work with URI schemes
if
not
_is_uri_path
(
profiler_dir
):
profiler_out_file
=
f
"
{
profiler_dir
}
/profiler_out_
{
rank
}
.txt"
with
open
(
profiler_out_file
,
"w"
)
as
f
:
with
open
(
profiler_out_file
,
"w"
)
as
f
:
print
(
table
,
file
=
f
)
print
(
table
,
file
=
f
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment