Skip to content

Commit b983f7d

Browse files
authored
Change op names to linear_8bit_act_xbit_weight
Differential Revision: D63347192 Pull Request resolved: #978
1 parent ae49375 commit b983f7d

28 files changed

+176
-193
lines changed

torchao/experimental/CMakeLists.txt

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ if(NOT TORCHAO_INCLUDE_DIRS)
2525
endif()
2626

2727
if (NOT TORCHAO_OP_TARGET)
28-
message(FATAL_ERROR "TORCHAO_OP_TARGET is not set. Set it to ATEN or EXECUTORCH.")
28+
message(FATAL_ERROR "TORCHAO_OP_TARGET is not set. Set it to aten or executorch.")
2929
endif()
3030

3131
if (NOT TORCHAO_PARALLEL_BACKEND)
32-
if (TORCHAO_OP_TARGET STREQUAL "ATEN")
33-
set(TORCHAO_PARALLEL_BACKEND "ATEN_OPENMP")
34-
elseif(TORCHAO_OP_TARGET STREQUAL "EXECUTORCH")
35-
set(TORCHAO_PARALLEL_BACKEND "EXECUTORCH")
32+
if (TORCHAO_OP_TARGET STREQUAL "aten")
33+
set(TORCHAO_PARALLEL_BACKEND "aten_openmp")
34+
elseif(TORCHAO_OP_TARGET STREQUAL "executorch")
35+
set(TORCHAO_PARALLEL_BACKEND "executorch")
3636
else()
3737
message(TORCHAO_PARALLEL_BACKEND "TORCHAO_PARALLEL_BACKEND is not set. Please set it directly or set TORCHAO_OP_TARGET to get a default.")
3838
endif()
@@ -46,9 +46,26 @@ include(CMakePrintHelpers)
4646
message("TORCHAO_INCLUDE_DIRS: ${TORCHAO_INCLUDE_DIRS}")
4747
include_directories(${TORCHAO_INCLUDE_DIRS})
4848

49+
if(TORCHAO_OP_TARGET STREQUAL "aten")
50+
add_library(torchao_ops_${TORCHAO_OP_TARGET} SHARED)
51+
elseif(TORCHAO_OP_TARGET STREQUAL "executorch")
52+
add_library(torchao_ops_${TORCHAO_OP_TARGET} STATIC)
53+
else()
54+
message(FATAL_ERROR "Unknown TORCHAO_OP_TARGET: ${TORCHAO_OP_TARGET}. Please choose one of: aten, executorch.")
55+
endif()
56+
4957
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
5058
# Defines target torchao_kernels_aarch64
5159
add_subdirectory(${TORCHAO_ROOT}/kernels/cpu/aarch64)
52-
add_subdirectory(${TORCHAO_ROOT}/ops/linear)
53-
add_subdirectory(${TORCHAO_ROOT}/ops/linear/linear_a8wxdq_op)
60+
add_subdirectory(${TORCHAO_ROOT}/ops/linear_8bit_act_xbit_weight)
61+
62+
target_link_libraries(
63+
torchao_ops_${TORCHAO_OP_TARGET} PRIVATE
64+
torchao_ops_linear_8bit_act_xbit_weight_${TORCHAO_OP_TARGET}
65+
)
5466
endif()
67+
68+
install(
69+
TARGETS torchao_ops_${TORCHAO_OP_TARGET}
70+
DESTINATION lib
71+
)

torchao/experimental/ops/linear/benchmarks/CMakeLists.txt renamed to torchao/experimental/ops/benchmarks/CMakeLists.txt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ set(CMAKE_CXX_STANDARD 17)
1111
set(CMAKE_BUILD_TYPE Release)
1212
add_compile_options("-Wall" "-Werror")
1313

14-
set(TORCHAO_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
15-
set(TORCHAO_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../../../../..)
14+
set(TORCHAO_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
15+
set(TORCHAO_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../../../..)
1616

1717
include(FetchContent)
1818
FetchContent_Declare(googlebenchmark
@@ -25,16 +25,20 @@ FetchContent_MakeAvailable(
2525

2626
include_directories(${TORCHAO_INCLUDE_DIRS})
2727

28-
set(TORCHAO_PARALLEL_BACKEND "OPENMP")
29-
add_subdirectory(${TORCHAO_ROOT}/ops/linear ${CMAKE_CURRENT_BINARY_DIR}/torchao_ops_linear_${TORCHAO_PARALLEL_BACKEND})
28+
set(TORCHAO_PARALLEL_BACKEND "openmp")
29+
30+
include(${TORCHAO_ROOT}/Utils.cmake)
31+
3032
add_subdirectory(${TORCHAO_ROOT}/kernels/cpu/aarch64 ${CMAKE_CURRENT_BINARY_DIR}/torchao_kernels_aarch64)
3133

32-
add_executable(benchmark_linear_operator benchmark_linear_operator.cpp)
34+
add_executable(benchmark_linear_8bit_act_xbit_weight
35+
benchmark_linear_8bit_act_xbit_weight.cpp
36+
${TORCHAO_ROOT}/ops/linear_8bit_act_xbit_weight/linear_8bit_act_xbit_weight.cpp
37+
)
38+
target_link_torchao_parallel_backend(benchmark_linear_8bit_act_xbit_weight "${TORCHAO_PARALLEL_BACKEND}")
3339
target_link_libraries(
34-
benchmark_linear_operator
40+
benchmark_linear_8bit_act_xbit_weight
3541
PRIVATE
3642
benchmark::benchmark
3743
torchao_kernels_aarch64
38-
torchao_ops_linear_${TORCHAO_PARALLEL_BACKEND}
3944
)
40-
target_link_torchao_parallel_backend(benchmark_linear_operator "${TORCHAO_PARALLEL_BACKEND}")

torchao/experimental/ops/linear/benchmarks/benchmark_linear_operator.cpp renamed to torchao/experimental/ops/benchmarks/benchmark_linear_8bit_act_xbit_weight.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
#include <benchmark/benchmark.h>
88
#include <torchao/experimental/kernels/cpu/aarch64/linear/linear.h>
99
#include <torchao/experimental/kernels/cpu/aarch64/tests/test_utils.h>
10-
#include <torchao/experimental/ops/linear/channelwise_8bit_activation_groupwise_lowbit_weight.h>
10+
#include <torchao/experimental/ops/linear_8bit_act_xbit_weight/linear_8bit_act_xbit_weight.h>
1111
#include <torchao/experimental/ops/memory.h>
1212
#include <torchao/experimental/ops/parallel.h>
1313
#include <vector>
1414

15-
using namespace torchao::ops::linear::
16-
channelwise_8bit_activation_groupwise_lowbit_weight;
15+
using namespace torchao::ops::linear_8bit_act_xbit_weight;
1716

1817
template <int weight_nbit, bool has_weight_zeros, bool has_bias, bool has_clamp>
1918
UKernelConfig get_ukernel_config() {
@@ -40,8 +39,7 @@ UKernelConfig get_ukernel_config() {
4039
}
4140

4241
template <int weight_nbit, bool has_weight_zeros, bool has_bias, bool has_clamp>
43-
static void channelwise_8bit_activation_groupwise_lowbit_weight(
44-
benchmark::State& state) {
42+
static void linear_8bit_act_xbit_weight(benchmark::State& state) {
4543
int m = state.range(0);
4644
int n = state.range(1);
4745
int k = state.range(2);
@@ -150,19 +148,20 @@ static void channelwise_8bit_activation_groupwise_lowbit_weight(
150148
} \
151149
}
152150

153-
#define BENCHMARK_CHANNELWISE_8BIT_ACTIVATION_GROUPWISE_LOWBIT_WEIGHT( \
154-
weight_nbit) \
155-
BENCHMARK(channelwise_8bit_activation_groupwise_lowbit_weight< \
156-
weight_nbit, \
157-
false /*has_weight_zeros*/, \
158-
false /*has_bias*/, \
159-
false /*has_clamp*/>) \
160-
->ArgsProduct(BENCHMARK_PARAMS) \
161-
->ArgNames( \
151+
#define BENCHMARK_LINEAR_8BIT_ACT_XBIT_WEIGHT(weight_nbit) \
152+
BENCHMARK(linear_8bit_act_xbit_weight< \
153+
weight_nbit, \
154+
false /*has_weight_zeros*/, \
155+
false /*has_bias*/, \
156+
false /*has_clamp*/>) \
157+
->ArgsProduct(BENCHMARK_PARAMS) \
158+
->ArgNames( \
162159
{"m", "n", "k", "group_size", "num_threads", "num_test_cases"});
163160

164-
BENCHMARK_CHANNELWISE_8BIT_ACTIVATION_GROUPWISE_LOWBIT_WEIGHT(3);
165-
BENCHMARK_CHANNELWISE_8BIT_ACTIVATION_GROUPWISE_LOWBIT_WEIGHT(4);
161+
BENCHMARK_LINEAR_8BIT_ACT_XBIT_WEIGHT(2);
162+
BENCHMARK_LINEAR_8BIT_ACT_XBIT_WEIGHT(3);
163+
BENCHMARK_LINEAR_8BIT_ACT_XBIT_WEIGHT(4);
164+
BENCHMARK_LINEAR_8BIT_ACT_XBIT_WEIGHT(5);
166165

167166
// Run the benchmark
168167
BENCHMARK_MAIN();

torchao/experimental/ops/linear/benchmarks/build_and_run_benchmarks.sh renamed to torchao/experimental/ops/benchmarks/build_and_run_benchmarks.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,4 @@ cmake -DTORCHAO_LIBRARIES=${TORCHAO_LIBRARIES} \
1717
cmake --build ${CMAKE_OUT}
1818

1919
# Run
20-
case "$1" in
21-
linear_operator) ${CMAKE_OUT}/benchmark_linear_operator; ;;
22-
*) echo "Unknown benchmark: $1. Please specify one of: linear_operator."; exit 1; ;;
23-
esac
20+
${CMAKE_OUT}/benchmark_linear_8bit_act_xbit_weight

torchao/experimental/ops/linear/CMakeLists.txt

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

torchao/experimental/ops/linear/linear_a8wxdq_op/CMakeLists.txt

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
cmake_minimum_required(VERSION 3.19)
8+
9+
include(${TORCHAO_ROOT}/Utils.cmake)
10+
11+
12+
if(TORCHAO_OP_TARGET STREQUAL "aten")
13+
message(STATUS "Building with TORCHAO_OP_TARGET=aten")
14+
find_package(Torch REQUIRED)
15+
add_library(torchao_ops_linear_8bit_act_xbit_weight_${TORCHAO_OP_TARGET} OBJECT
16+
linear_8bit_act_xbit_weight.cpp
17+
op_linear_8bit_act_xbit_weight_aten.cpp
18+
)
19+
target_link_torchao_parallel_backend(torchao_ops_linear_8bit_act_xbit_weight_${TORCHAO_OP_TARGET} "${TORCHAO_PARALLEL_BACKEND}")
20+
target_link_libraries(torchao_ops_linear_8bit_act_xbit_weight_${TORCHAO_OP_TARGET} PRIVATE torchao_kernels_aarch64)
21+
target_include_directories(torchao_ops_linear_8bit_act_xbit_weight_${TORCHAO_OP_TARGET} PRIVATE "${TORCH_INCLUDE_DIRS}")
22+
target_link_libraries(torchao_ops_linear_8bit_act_xbit_weight_${TORCHAO_OP_TARGET} PRIVATE "${TORCH_LIBRARIES}")
23+
target_compile_definitions(torchao_ops_linear_8bit_act_xbit_weight_${TORCHAO_OP_TARGET} PRIVATE USE_ATEN=1)
24+
elseif(TORCHAO_OP_TARGET STREQUAL "executorch")
25+
message(STATUS "Building with TORCHAO_OP_TARGET=executorch")
26+
add_library(torchao_ops_linear_8bit_act_xbit_weight_${TORCHAO_OP_TARGET} OBJECT
27+
linear_8bit_act_xbit_weight.cpp
28+
op_linear_8bit_act_xbit_weight_executorch/w2s.cpp
29+
op_linear_8bit_act_xbit_weight_executorch/w2sz.cpp
30+
op_linear_8bit_act_xbit_weight_executorch/w3s.cpp
31+
op_linear_8bit_act_xbit_weight_executorch/w3sz.cpp
32+
op_linear_8bit_act_xbit_weight_executorch/w4s.cpp
33+
op_linear_8bit_act_xbit_weight_executorch/w4sz.cpp
34+
op_linear_8bit_act_xbit_weight_executorch/w5s.cpp
35+
op_linear_8bit_act_xbit_weight_executorch/w5sz.cpp
36+
)
37+
target_link_torchao_parallel_backend(torchao_ops_linear_8bit_act_xbit_weight_${TORCHAO_OP_TARGET} "${TORCHAO_PARALLEL_BACKEND}")
38+
target_include_directories(torchao_ops_linear_8bit_act_xbit_weight_${TORCHAO_OP_TARGET} PRIVATE "${EXECUTORCH_INCLUDE_DIRS}")
39+
target_compile_definitions(torchao_ops_linear_8bit_act_xbit_weight_${TORCHAO_OP_TARGET} PRIVATE USE_EXECUTORCH=1)
40+
target_link_libraries(torchao_ops_linear_8bit_act_xbit_weight_${TORCHAO_OP_TARGET} PRIVATE "${EXECUTORCH_LIBRARIES}")
41+
target_link_libraries(torchao_ops_linear_8bit_act_xbit_weight_${TORCHAO_OP_TARGET} PRIVATE torchao_kernels_aarch64)
42+
else()
43+
message(FATAL_ERROR "Unknown TORCHAO_OP_TARGET: ${TORCHAO_OP_TARGET}. Please choose one of: aten, executorch.")
44+
endif()

torchao/experimental/ops/linear/examples/CMakeLists.txt renamed to torchao/experimental/ops/linear_8bit_act_xbit_weight/examples/CMakeLists.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,29 @@ set(TORCHAO_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../../../../..)
1717

1818
include_directories(${TORCHAO_INCLUDE_DIRS})
1919

20-
set(TORCHAO_PARALLEL_BACKEND "OPENMP")
21-
add_subdirectory(${TORCHAO_ROOT}/ops/linear ${CMAKE_CURRENT_BINARY_DIR}/torchao_ops_linear_${TORCHAO_PARALLEL_BACKEND})
20+
set(TORCHAO_PARALLEL_BACKEND "openmp")
2221
add_subdirectory(${TORCHAO_ROOT}/kernels/cpu/aarch64 ${CMAKE_CURRENT_BINARY_DIR}/torchao_kernels_aarch64)
2322

2423
include(${TORCHAO_ROOT}/Utils.cmake)
2524

26-
add_executable(separate_function_wrappers separate_function_wrappers.cpp)
25+
add_executable(separate_function_wrappers
26+
separate_function_wrappers.cpp
27+
${TORCHAO_ROOT}/ops/linear_8bit_act_xbit_weight/linear_8bit_act_xbit_weight.cpp
28+
)
2729
target_link_libraries(
2830
separate_function_wrappers
2931
PRIVATE
3032
torchao_kernels_aarch64
31-
torchao_ops_linear_${TORCHAO_PARALLEL_BACKEND}
3233
)
3334
target_link_torchao_parallel_backend(separate_function_wrappers "${TORCHAO_PARALLEL_BACKEND}")
3435

35-
add_executable(stateful_class_wrapper stateful_class_wrapper.cpp)
36+
add_executable(stateful_class_wrapper
37+
stateful_class_wrapper.cpp
38+
${TORCHAO_ROOT}/ops/linear_8bit_act_xbit_weight/linear_8bit_act_xbit_weight.cpp
39+
)
3640
target_link_libraries(
3741
stateful_class_wrapper
3842
PRIVATE
3943
torchao_kernels_aarch64
40-
torchao_ops_linear_${TORCHAO_PARALLEL_BACKEND}
4144
)
4245
target_link_torchao_parallel_backend(stateful_class_wrapper "${TORCHAO_PARALLEL_BACKEND}")
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55
// LICENSE file in the root directory of this source tree.
66

77
#pragma once
8-
#include <torchao/experimental/ops/linear/channelwise_8bit_activation_groupwise_lowbit_weight.h>
8+
#include <torchao/experimental/ops/linear_8bit_act_xbit_weight/linear_8bit_act_xbit_weight.h>
99
#include <torchao/experimental/ops/macro.h>
1010
#include <torchao/experimental/ops/memory.h>
1111
#include <cassert>
1212
#include <optional>
1313

14-
namespace torchao::ops::linear::
15-
channelwise_8bit_activation_groupwise_lowbit_weight {
14+
namespace torchao::ops::linear_8bit_act_xbit_weight {
1615

17-
class Channelwise8BitActivationGroupwiseLowbitWeightLinearOperator {
16+
class Linear8BitActXBitWeightOperator {
1817
private:
1918
torchao::aligned_byte_ptr packed_weight_data_{nullptr, nullptr};
2019
int packed_weight_data_size_{0};
@@ -40,7 +39,7 @@ class Channelwise8BitActivationGroupwiseLowbitWeightLinearOperator {
4039
LinearTileSchedulingPolicy linear_scheduling_policy_;
4140

4241
public:
43-
Channelwise8BitActivationGroupwiseLowbitWeightLinearOperator(
42+
Linear8BitActXBitWeightOperator(
4443
UKernelConfig ukernel_config,
4544
int n,
4645
int k,
@@ -195,4 +194,4 @@ class Channelwise8BitActivationGroupwiseLowbitWeightLinearOperator {
195194
}
196195
};
197196
} // namespace
198-
// torchao::ops::linear::channelwise_8bit_activation_groupwise_lowbit_weight
197+
// torchao::ops::linear_8bit_act_xbit_weight

torchao/experimental/ops/linear/examples/separate_function_wrappers.cpp renamed to torchao/experimental/ops/linear_8bit_act_xbit_weight/examples/separate_function_wrappers.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <torchao/experimental/kernels/cpu/aarch64/linear/linear.h>
88
#include <torchao/experimental/kernels/cpu/aarch64/tests/test_utils.h>
9-
#include <torchao/experimental/ops/linear/channelwise_8bit_activation_groupwise_lowbit_weight.h>
9+
#include <torchao/experimental/ops/linear_8bit_act_xbit_weight/linear_8bit_act_xbit_weight.h>
1010
#include <torchao/experimental/ops/memory.h>
1111
#include <torchao/experimental/ops/parallel.h>
1212
#include <iostream>
@@ -22,8 +22,7 @@
2222
// one stateful class, but not all surfaces support this (see
2323
// examples/stateful_class_wrapper.cpp for an example of this).
2424

25-
namespace torchao::ops::linear::
26-
channelwise_8bit_activation_groupwise_lowbit_weight {
25+
namespace torchao::ops::linear_8bit_act_xbit_weight {
2726

2827
template <int weight_nbit, bool has_weight_zeros, bool has_bias, bool has_clamp>
2928
UKernelConfig get_ukernel_config() {
@@ -141,11 +140,10 @@ void linear_operator(
141140
}
142141

143142
} // namespace
144-
// torchao::ops::linear::channelwise_8bit_activation_groupwise_lowbit_weight
143+
// torchao::ops::linear_8bit_act_xbit_weight
145144

146145
int main() {
147-
using namespace torchao::ops::linear::
148-
channelwise_8bit_activation_groupwise_lowbit_weight;
146+
using namespace torchao::ops::linear_8bit_act_xbit_weight;
149147

150148
torchao::set_num_threads(8);
151149
std::cout << "Using " << torchao::get_num_threads() << " threads."

torchao/experimental/ops/linear/examples/stateful_class_wrapper.cpp renamed to torchao/experimental/ops/linear_8bit_act_xbit_weight/examples/stateful_class_wrapper.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <torchao/experimental/kernels/cpu/aarch64/linear/linear.h>
88
#include <torchao/experimental/kernels/cpu/aarch64/tests/test_utils.h>
9-
#include <torchao/experimental/ops/linear/examples/Channelwise8BitActivationGroupwiseLowbitWeightLinearOperator.h>
9+
#include <torchao/experimental/ops/linear_8bit_act_xbit_weight/examples/Linear8BitActXBitWeightOperator.h>
1010
#include <torchao/experimental/ops/parallel.h>
1111
#include <iostream>
1212
#include <vector>
@@ -22,8 +22,7 @@
2222
// examples/separate_function_wrappers.cpp for an example of how to split the
2323
// operations into two steps.
2424

25-
using namespace torchao::ops::linear::
26-
channelwise_8bit_activation_groupwise_lowbit_weight;
25+
using namespace torchao::ops::linear_8bit_act_xbit_weight;
2726

2827
template <int weight_nbit, bool has_weight_zeros, bool has_bias, bool has_clamp>
2928
UKernelConfig get_ukernel_config() {
@@ -81,7 +80,7 @@ int main() {
8180
get_ukernel_config<weight_nbit, has_weight_zeros, has_bias, has_clamp>();
8281

8382
auto linear_operator =
84-
Channelwise8BitActivationGroupwiseLowbitWeightLinearOperator(
83+
Linear8BitActXBitWeightOperator(
8584
ukernel_config,
8685
n,
8786
k,

0 commit comments

Comments
 (0)