Skip to content

Commit b04c93c

Browse files
committed
up
1 parent 235b736 commit b04c93c

File tree

21 files changed

+83
-466
lines changed

21 files changed

+83
-466
lines changed

.github/workflows/torchao_experimental_test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
run: |
3535
conda activate venv
3636
pip install torch --index-url "https://download.pytorch.org/whl/nightly/cpu"
37+
pip install executorch
3738
pip install numpy
3839
pip install pytest
3940
pip install parameterized
@@ -57,6 +58,12 @@ jobs:
5758
sh build_and_run_tests.sh
5859
rm -rf /tmp/cmake-out
5960
popd
61+
- name: ET ops build
62+
run: |
63+
conda activate venv
64+
pushd torchao/experimental
65+
sh build_torchao_ops.sh executorch
66+
popd
6067
6168
test-mps-ops:
6269
strategy:

torchao/experimental/build_torchao_ops.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export CMAKE_OUT=cmake-out
2121
cmake -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} \
2222
-DCMAKE_INSTALL_PREFIX=${CMAKE_OUT} \
2323
-DTORCHAO_BUILD_EXECUTORCH_OPS="${TORCHAO_BUILD_EXECUTORCH_OPS}" \
24+
-DTORCHAO_BUILD_CPU_AARCH64=ON \
2425
-S . \
2526
-B ${CMAKE_OUT}
2627
cmake --build ${CMAKE_OUT} -j 16 --target install --config Release

torchao/experimental/ops/embedding_xbit/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ if(TORCHAO_BUILD_EXECUTORCH_OPS)
2727
# libextension_threadpool.a
2828
# libcpuinfo.a
2929
# libpthreadpool.a
30+
if(NOT DEFINED EXECUTORCH_INCLUDE_DIRS AND NOT DEFINED EXECUTORCH_LIBRARIES)
31+
message(WARNING "EXECUTORCH_INCLUDE_DIRS and EXECUTORCH_LIBRARIES are not defined. Looking for ExecuTorch.")
32+
find_package(ExecuTorch HINTS ${CMAKE_PREFIX_PATH}/executorch/share/cmake)
33+
endif()
3034
add_library(torchao_ops_embedding_xbit_executorch OBJECT
3135
op_embedding_xbit_executorch.cpp
3236
)

torchao/experimental/ops/linear_8bit_act_xbit_weight/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ if(TORCHAO_BUILD_EXECUTORCH_OPS)
4141
# libextension_threadpool.a
4242
# libcpuinfo.a
4343
# libpthreadpool.a
44+
if(NOT DEFINED EXECUTORCH_INCLUDE_DIRS AND NOT DEFINED EXECUTORCH_LIBRARIES)
45+
message(WARNING "EXECUTORCH_INCLUDE_DIRS and EXECUTORCH_LIBRARIES are not defined. Looking for ExecuTorch.")
46+
find_package(ExecuTorch HINTS ${CMAKE_PREFIX_PATH}/executorch/share/cmake)
47+
endif()
4448
# find_package(ExecuTorch HINTS ${CMAKE_PREFIX_PATH}/executorch/share/cmake)
45-
file(GLOB _SRCS "${CMAKE_CURRENT_SOURCE_DIR}/op_linear_8bit_act_xbit_weight_executorch/*.cpp")
49+
# file(GLOB _SRCS "${CMAKE_CURRENT_SOURCE_DIR}/op_linear_8bit_act_xbit_weight_executorch/*.cpp")
4650
add_library(torchao_ops_linear_8bit_act_xbit_weight_executorch OBJECT
4751
linear_8bit_act_xbit_weight.cpp
48-
${_SRCS}
52+
op_linear_8bit_act_xbit_weight_executorch.cpp
4953
)
5054
target_link_torchao_parallel_backend(torchao_ops_linear_8bit_act_xbit_weight_executorch executorch)
5155
target_include_directories(torchao_ops_linear_8bit_act_xbit_weight_executorch PRIVATE "${EXECUTORCH_INCLUDE_DIRS}")
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <torchao/experimental/ops/linear_8bit_act_xbit_weight/op_linear_8bit_act_xbit_weight-impl.h>
2+
3+
#define DEFINE_OP(weight_nbit) \
4+
Tensor _op_out_0zp_##weight_nbit( \
5+
RuntimeContext &ctx, const Tensor &activations, \
6+
const Tensor &packed_weights, const int64_t &group_size, \
7+
const int64_t &n, const int64_t &k, Tensor &out) { \
8+
(void)ctx; \
9+
linear_out_cpu<weight_nbit, false>(activations, packed_weights, \
10+
group_size, n, k, out); \
11+
return out; \
12+
} \
13+
Tensor _op_out_zp_##weight_nbit( \
14+
RuntimeContext &ctx, const Tensor &activations, \
15+
const Tensor &packed_weights, const int64_t &group_size, \
16+
const int64_t &n, const int64_t &k, Tensor &out) { \
17+
(void)ctx; \
18+
linear_out_cpu<weight_nbit, true>(activations, packed_weights, group_size, \
19+
n, k, out); \
20+
return out; \
21+
}
22+
23+
#define REGISTER_0ZP(weight_nbit) \
24+
EXECUTORCH_LIBRARY(torchao, \
25+
"_linear_8bit_act_" #weight_nbit "bit0zp_weight.out", \
26+
_op_out_0zp_##weight_nbit)
27+
28+
#define REGISTER_ZP(weight_nbit) \
29+
EXECUTORCH_LIBRARY(torchao, \
30+
"_linear_8bit_act_" #weight_nbit "bit_weight.out", \
31+
_op_out_zp_##weight_nbit)
32+
33+
// This looks a bit ridiculous, but I could not get it to compile with two
34+
// EXECUTORCH_LIBRARY nested inside DEFINE_OP
35+
DEFINE_OP(1)
36+
REGISTER_0ZP(1);
37+
REGISTER_ZP(1);
38+
39+
DEFINE_OP(2)
40+
REGISTER_0ZP(2);
41+
REGISTER_ZP(2);
42+
43+
DEFINE_OP(3)
44+
REGISTER_0ZP(3);
45+
REGISTER_ZP(3);
46+
47+
DEFINE_OP(4)
48+
REGISTER_0ZP(4);
49+
REGISTER_ZP(4);
50+
51+
DEFINE_OP(5)
52+
REGISTER_0ZP(5);
53+
REGISTER_ZP(5);
54+
55+
DEFINE_OP(6)
56+
REGISTER_0ZP(6);
57+
REGISTER_ZP(6);
58+
59+
DEFINE_OP(7)
60+
REGISTER_0ZP(7);
61+
REGISTER_ZP(7);
62+
63+
DEFINE_OP(8)
64+
REGISTER_0ZP(8);
65+
REGISTER_ZP(8);

torchao/experimental/ops/linear_8bit_act_xbit_weight/op_linear_8bit_act_xbit_weight_executorch/w1s.cpp

Lines changed: 0 additions & 29 deletions
This file was deleted.

torchao/experimental/ops/linear_8bit_act_xbit_weight/op_linear_8bit_act_xbit_weight_executorch/w1sz.cpp

Lines changed: 0 additions & 29 deletions
This file was deleted.

torchao/experimental/ops/linear_8bit_act_xbit_weight/op_linear_8bit_act_xbit_weight_executorch/w2s.cpp

Lines changed: 0 additions & 29 deletions
This file was deleted.

torchao/experimental/ops/linear_8bit_act_xbit_weight/op_linear_8bit_act_xbit_weight_executorch/w2sz.cpp

Lines changed: 0 additions & 29 deletions
This file was deleted.

torchao/experimental/ops/linear_8bit_act_xbit_weight/op_linear_8bit_act_xbit_weight_executorch/w3s.cpp

Lines changed: 0 additions & 29 deletions
This file was deleted.

torchao/experimental/ops/linear_8bit_act_xbit_weight/op_linear_8bit_act_xbit_weight_executorch/w3sz.cpp

Lines changed: 0 additions & 29 deletions
This file was deleted.

torchao/experimental/ops/linear_8bit_act_xbit_weight/op_linear_8bit_act_xbit_weight_executorch/w4s.cpp

Lines changed: 0 additions & 29 deletions
This file was deleted.

torchao/experimental/ops/linear_8bit_act_xbit_weight/op_linear_8bit_act_xbit_weight_executorch/w4sz.cpp

Lines changed: 0 additions & 29 deletions
This file was deleted.

torchao/experimental/ops/linear_8bit_act_xbit_weight/op_linear_8bit_act_xbit_weight_executorch/w5s.cpp

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)