Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
codecritic
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ziyuan Nan
codecritic
Commits
1a4460f9
Commit
1a4460f9
authored
Dec 03, 2024
by
nanziyuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: replace stack with generator for 3x performance improvement
parent
030769db
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
33 deletions
+12
-33
codecritic/utils/vllm_new.py
+12
-33
No files found.
codecritic/utils/vllm_new.py
View file @
1a4460f9
...
...
@@ -5,7 +5,6 @@ import multiprocessing
from
itertools
import
chain
,
combinations
from
functools
import
partial
import
subprocess
import
unicodedata
import
numpy
as
np
...
...
@@ -62,39 +61,19 @@ def get_gpu_topology():
def
comb_group
(
n
,
k
):
comb_stack
,
lst_stack
=
[],
[]
def
comb_pivot
(
lst
):
"""
lst should be sorted
"""
pivot
=
lst
[
0
]
for
other
in
combinations
(
lst
[
1
:],
k
-
1
):
yield
(
pivot
,)
+
other
def
fill_stack
():
lst
=
[
x
for
x
in
range
(
n
)
if
x
not
in
list
(
chain
(
*
lst_stack
))]
stack_len
=
len
(
comb_stack
)
for
_
in
range
((
n
//
k
)
-
stack_len
):
new_comb
=
comb_pivot
(
lst
)
new_group
=
next
(
new_comb
)
comb_stack
.
append
(
new_comb
)
lst_stack
.
append
(
new_group
)
lst
=
[
x
for
x
in
lst
if
x
not
in
new_group
]
fill_stack
()
yield
lst_stack
.
copy
()
while
len
(
comb_stack
)
>
0
:
new_group
=
next
(
comb_stack
[
-
1
],
None
)
if
new_group
:
lst_stack
[
-
1
]
=
new_group
fill_stack
()
yield
lst_stack
.
copy
()
groups
=
[]
def
helper
(
lst
):
if
len
(
lst
)
==
0
:
yield
groups
.
copy
()
else
:
comb_stack
.
pop
()
lst_stack
.
pop
()
head
,
*
rest
=
lst
for
group
in
combinations
(
rest
,
k
-
1
):
groups
.
append
((
head
,)
+
group
)
yield
from
helper
([
x
for
x
in
rest
if
x
not
in
group
])
groups
.
pop
()
yield
from
helper
(
list
(
range
(
n
)))
def
get_optimal_groups
(
matrix
,
index
,
k
):
...
...
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