Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jerrrrry
infinicore
Commits
f49235e3
Commit
f49235e3
authored
Jun 30, 2025
by
Zimin Li
Browse files
issue/288: improve the compatibility of the torch implementations of gemm and random sample
parent
a0abcb2c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
7 deletions
+15
-7
test/infiniop/gemm.py
test/infiniop/gemm.py
+8
-5
test/infiniop/random_sample.py
test/infiniop/random_sample.py
+7
-2
No files found.
test/infiniop/gemm.py
View file @
f49235e3
...
...
@@ -57,11 +57,14 @@ infiniopGemmDescriptor_t = POINTER(GemmDescriptor)
# PyTorch implementation for matrix multiplication
def
gemm
(
d
,
_c
,
beta
,
_a
,
_b
,
alpha
):
try
:
if
_c
.
ndim
==
2
:
torch
.
addmm
(
_c
,
_a
,
_b
,
beta
=
beta
,
alpha
=
alpha
,
out
=
d
)
elif
_c
.
ndim
==
3
:
torch
.
baddbmm
(
_c
,
_a
,
_b
,
beta
=
beta
,
alpha
=
alpha
,
out
=
d
)
else
:
raise
except
Exception
:
torch
.
matmul
(
_a
,
_b
,
out
=
d
)
d
.
mul_
(
alpha
).
add_
(
_c
,
alpha
=
beta
)
...
...
test/infiniop/random_sample.py
View file @
f49235e3
...
...
@@ -68,7 +68,12 @@ def random_sample(data, random_val, topp, topk, voc, temperature):
k_index
=
min
(
topk
,
voc
)
-
1
threshold
=
min
(
cum_probs
[
k_index
],
topp
)
*
random_val
try
:
idx
=
torch
.
searchsorted
(
cum_probs
,
threshold
)
except
Exception
:
# Fallback for manual search if torch.searchsorted is not supported
indices
=
(
cum_probs
>=
threshold
).
nonzero
(
as_tuple
=
True
)[
0
]
idx
=
indices
[
0
]
if
indices
.
numel
()
>
0
else
torch
.
tensor
(
len
(
cum_probs
)
-
1
,
device
=
cum_probs
.
device
)
return
sorted_indices
[
idx
]
return
torch
.
argmax
(
data
)
...
...
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