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
bf5062d5
Unverified
Commit
bf5062d5
authored
Jun 10, 2025
by
PanZezhong1725
Committed by
GitHub
Jun 10, 2025
Browse files
Merge pull request #249 from InfiniTensor/issue/228
issue/228: swiglu测例0步长添加
parents
de0fa8bf
22a3115c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
39 additions
and
30 deletions
+39
-30
src/infiniop-test/src/ops/random_sample.cpp
src/infiniop-test/src/ops/random_sample.cpp
+1
-1
test/infiniop-test/test_generate/__init__.py
test/infiniop-test/test_generate/__init__.py
+1
-1
test/infiniop-test/test_generate/infiniop_test.py
test/infiniop-test/test_generate/infiniop_test.py
+7
-0
test/infiniop-test/test_generate/testcases/add.py
test/infiniop-test/test_generate/testcases/add.py
+3
-15
test/infiniop-test/test_generate/testcases/clip.py
test/infiniop-test/test_generate/testcases/clip.py
+22
-12
test/infiniop-test/test_generate/testcases/swiglu.py
test/infiniop-test/test_generate/testcases/swiglu.py
+5
-1
No files found.
src/infiniop-test/src/ops/random_sample.cpp
View file @
bf5062d5
...
...
@@ -110,7 +110,7 @@ std::vector<std::string> Test::tensor_names() {
}
std
::
vector
<
std
::
string
>
Test
::
output_names
()
{
return
{
"result"
};
return
{};
}
std
::
string
Test
::
toString
()
const
{
...
...
test/infiniop-test/test_generate/__init__.py
View file @
bf5062d5
from
.infiniop_test
import
InfiniopTestCase
,
InfiniopTestWriter
,
np_dtype_to_ggml
,
gguf_strides
,
contiguous_gguf_strides
from
.infiniop_test
import
InfiniopTestCase
,
InfiniopTestWriter
,
np_dtype_to_ggml
,
gguf_strides
,
contiguous_gguf_strides
,
process_zero_stride_tensor
test/infiniop-test/test_generate/infiniop_test.py
View file @
bf5062d5
...
...
@@ -37,6 +37,13 @@ def contiguous_gguf_strides(shape: tuple[int, ...]) -> list[int]:
acc
*=
size
return
strides
[::
-
1
]
def
process_zero_stride_tensor
(
tensor
,
stride
=
None
):
if
stride
:
slices
=
tuple
(
slice
(
0
,
1
)
if
s
==
0
else
slice
(
None
)
for
s
in
stride
)
return
tensor
[
slices
]
else
:
return
tensor
class
InfiniopTestCase
:
op_name
:
str
...
...
test/infiniop-test/test_generate/testcases/add.py
View file @
bf5062d5
...
...
@@ -4,7 +4,7 @@ import gguf
from
typing
import
List
from
numpy.lib.stride_tricks
import
as_strided
from
..
import
InfiniopTestWriter
,
InfiniopTestCase
,
np_dtype_to_ggml
,
gguf_strides
,
contiguous_gguf_strides
from
..
import
InfiniopTestWriter
,
InfiniopTestCase
,
np_dtype_to_ggml
,
gguf_strides
,
contiguous_gguf_strides
,
process_zero_stride_tensor
def
add
(
...
...
@@ -13,17 +13,6 @@ def add(
):
return
a
+
b
def
process_tensor
(
a
,
b
,
stride_a
=
None
,
stride_b
=
None
):
def
normalize_stride
(
tensor
,
stride
):
if
stride
:
slices
=
tuple
(
slice
(
0
,
1
)
if
s
==
0
else
slice
(
None
)
for
s
in
stride
)
return
tensor
[
slices
]
else
:
return
tensor
a_unique
=
normalize_stride
(
a
,
stride_a
)
b_unique
=
normalize_stride
(
b
,
stride_b
)
return
a_unique
,
b_unique
class
AddTestCase
(
InfiniopTestCase
):
def
__init__
(
...
...
@@ -111,9 +100,8 @@ if __name__ == "__main__":
a
=
np
.
random
.
rand
(
*
shape
).
astype
(
dtype
)
b
=
np
.
random
.
rand
(
*
shape
).
astype
(
dtype
)
c
=
np
.
empty
(
tuple
(
0
for
_
in
shape
),
dtype
=
dtype
)
a
,
b
=
process_tensor
(
a
,
b
,
stride_a
,
stride_b
)
if
stride_c
is
None
:
stride_c
=
contiguous_gguf_strides
(
shape
)
a
=
process_zero_stride_tensor
(
a
,
stride_a
)
b
=
process_zero_stride_tensor
(
b
,
stride_b
)
test_case
=
AddTestCase
(
a
=
a
,
shape_a
=
shape
,
...
...
test/infiniop-test/test_generate/testcases/clip.py
View file @
bf5062d5
...
...
@@ -2,7 +2,7 @@ import numpy as np
import
gguf
from
typing
import
List
,
Optional
,
Tuple
from
..
import
InfiniopTestWriter
,
InfiniopTestCase
,
np_dtype_to_ggml
,
gguf_strides
from
..
import
InfiniopTestWriter
,
InfiniopTestCase
,
np_dtype_to_ggml
,
gguf_strides
,
contiguous_gguf_strides
def
clip
(
...
...
@@ -52,6 +52,7 @@ class ClipTestCase(InfiniopTestCase):
max_val
:
np
.
ndarray
,
max_stride
:
Optional
[
List
[
int
]],
y
:
np
.
ndarray
,
y_shape
:
Optional
[
List
[
int
]],
y_stride
:
Optional
[
List
[
int
]],
):
super
().
__init__
(
"clip"
)
...
...
@@ -62,6 +63,7 @@ class ClipTestCase(InfiniopTestCase):
self
.
max_val
=
max_val
self
.
max_stride
=
max_stride
self
.
y
=
y
self
.
y_shape
=
y_shape
self
.
y_stride
=
y_stride
def
write_test
(
self
,
test_writer
:
"InfiniopTestWriter"
):
...
...
@@ -69,13 +71,17 @@ class ClipTestCase(InfiniopTestCase):
# Add strides as arrays if they exist
if
self
.
x_stride
is
not
None
:
test_writer
.
add_array
(
test_writer
.
gguf_key
(
"x.strides"
),
self
.
x_stride
)
test_writer
.
add_array
(
test_writer
.
gguf_key
(
"x.strides"
),
gguf_strides
(
*
self
.
x_stride
)
)
if
self
.
min_stride
is
not
None
:
test_writer
.
add_array
(
test_writer
.
gguf_key
(
"min_val.strides"
),
self
.
min_stride
)
test_writer
.
add_array
(
test_writer
.
gguf_key
(
"min_val.strides"
),
gguf_strides
(
*
self
.
min_stride
)
)
if
self
.
max_stride
is
not
None
:
test_writer
.
add_array
(
test_writer
.
gguf_key
(
"max_val.strides"
),
self
.
max_stride
)
if
self
.
y_stride
is
not
None
:
test_writer
.
add_array
(
test_writer
.
gguf_key
(
"y.strides"
),
self
.
y_stride
)
test_writer
.
add_array
(
test_writer
.
gguf_key
(
"max_val.strides"
),
gguf_strides
(
*
self
.
max_stride
))
if
self
.
y_shape
is
not
None
:
test_writer
.
add_array
(
test_writer
.
gguf_key
(
"y.shape"
),
self
.
y_shape
)
test_writer
.
add_array
(
test_writer
.
gguf_key
(
"y.strides"
),
gguf_strides
(
*
self
.
y_stride
if
self
.
y_stride
is
not
None
else
contiguous_gguf_strides
(
self
.
y_shape
))
)
# Add tensors to the test
test_writer
.
add_tensor
(
...
...
@@ -153,7 +159,7 @@ if __name__ == "__main__":
x
=
random_tensor
(
shape
,
dtype
)
min_tensor
=
np
.
full
(
shape
,
min_val
,
dtype
=
dtype
)
max_tensor
=
np
.
full
(
shape
,
max_val
,
dtype
=
dtype
)
y
=
np
.
zeros
(
shape
,
dtype
=
dtype
)
y
=
np
.
empty
(
tuple
(
0
for
_
in
shape
)
,
dtype
=
dtype
)
test_cases
.
append
(
ClipTestCase
(
...
...
@@ -164,6 +170,7 @@ if __name__ == "__main__":
max_val
=
max_tensor
,
max_stride
=
None
,
y
=
y
,
y_shape
=
shape
,
y_stride
=
None
)
)
...
...
@@ -172,15 +179,15 @@ if __name__ == "__main__":
for
shape
in
[
s
for
s
in
shapes
if
len
(
s
)
==
2
]:
for
dtype
in
dtypes
:
# Row-major stride
row_stride
=
gguf_strides
(
shape
[
1
],
1
)
row_stride
=
(
shape
[
1
],
1
)
# Column-major stride
col_stride
=
gguf_strides
(
1
,
shape
[
0
])
col_stride
=
(
1
,
shape
[
0
])
# Test case with row-major input and output
x
=
random_tensor
(
shape
,
dtype
)
min_tensor
=
np
.
full
(
shape
,
-
1.0
,
dtype
=
dtype
)
max_tensor
=
np
.
full
(
shape
,
1.0
,
dtype
=
dtype
)
y
=
np
.
zeros
(
shape
,
dtype
=
dtype
)
y
=
np
.
empty
(
tuple
(
0
for
_
in
shape
)
,
dtype
=
dtype
)
test_cases
.
append
(
ClipTestCase
(
...
...
@@ -191,6 +198,7 @@ if __name__ == "__main__":
max_val
=
max_tensor
,
max_stride
=
row_stride
,
y
=
y
,
y_shape
=
shape
,
y_stride
=
row_stride
)
)
...
...
@@ -199,7 +207,7 @@ if __name__ == "__main__":
x
=
random_tensor
(
shape
,
dtype
)
min_tensor
=
np
.
full
(
shape
,
-
1.0
,
dtype
=
dtype
)
max_tensor
=
np
.
full
(
shape
,
1.0
,
dtype
=
dtype
)
y
=
np
.
zeros
(
shape
,
dtype
=
dtype
)
y
=
np
.
empty
(
tuple
(
0
for
_
in
shape
)
,
dtype
=
dtype
)
test_cases
.
append
(
ClipTestCase
(
...
...
@@ -210,6 +218,7 @@ if __name__ == "__main__":
max_val
=
max_tensor
,
max_stride
=
col_stride
,
y
=
y
,
y_shape
=
shape
,
y_stride
=
col_stride
)
)
...
...
@@ -218,7 +227,7 @@ if __name__ == "__main__":
x
=
random_tensor
(
shape
,
dtype
)
min_tensor
=
np
.
full
(
shape
,
-
1.0
,
dtype
=
dtype
)
max_tensor
=
np
.
full
(
shape
,
1.0
,
dtype
=
dtype
)
y
=
np
.
zeros
(
shape
,
dtype
=
dtype
)
y
=
np
.
empty
(
tuple
(
0
for
_
in
shape
)
,
dtype
=
dtype
)
test_cases
.
append
(
ClipTestCase
(
...
...
@@ -229,6 +238,7 @@ if __name__ == "__main__":
max_val
=
max_tensor
,
max_stride
=
row_stride
,
y
=
y
,
y_shape
=
shape
,
y_stride
=
col_stride
)
)
...
...
test/infiniop-test/test_generate/testcases/swiglu.py
View file @
bf5062d5
...
...
@@ -2,7 +2,7 @@ import numpy as np
import
gguf
from
typing
import
List
from
..
import
InfiniopTestWriter
,
InfiniopTestCase
,
np_dtype_to_ggml
,
gguf_strides
,
contiguous_gguf_strides
from
..
import
InfiniopTestWriter
,
InfiniopTestCase
,
np_dtype_to_ggml
,
gguf_strides
,
contiguous_gguf_strides
,
process_zero_stride_tensor
def
swiglu
(
...
...
@@ -92,6 +92,8 @@ if __name__ == "__main__":
((
2
,
3
,
400
),
(
1200
,
400
,
1
),
(
1200
,
400
,
1
),
(
1
,
2
,
6
)),
((
4
,
4
,
5632
),
None
,
None
,
None
),
((
4
,
4
,
5632
),
(
45056
,
5632
,
1
),
(
45056
,
5632
,
1
),
(
45056
,
5632
,
1
)),
((
13
,
4
),
(
0
,
1
),
None
,
None
),
((
13
,
4
,
4
),
(
4
,
0
,
1
),
(
0
,
4
,
1
),
None
),
]
_TENSOR_DTYPES_
=
[
np
.
float32
,
np
.
float16
]
...
...
@@ -100,6 +102,8 @@ if __name__ == "__main__":
a
=
np
.
random
.
rand
(
*
shape
).
astype
(
dtype
)
b
=
np
.
random
.
rand
(
*
shape
).
astype
(
dtype
)
c
=
np
.
empty
(
tuple
(
0
for
_
in
shape
),
dtype
=
dtype
)
a
=
process_zero_stride_tensor
(
a
,
stride_a
)
b
=
process_zero_stride_tensor
(
b
,
stride_b
)
test_case
=
SwiGLUTestCase
(
a
=
a
,
shape_a
=
list
(
shape
),
...
...
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