Skip to content

Commit ad61822

Browse files
authored
Remove temp build files from torchao (#1551)
Summary: Removes temp build artifacts from experimental. Now the kernels are built and loaded with `USE_CPP=1 pip install .` from ao. Reviewed By: jerryzh168 Differential Revision: D67807207
1 parent 1651ffa commit ad61822

4 files changed

+9
-129
lines changed

torchao/_models/llama/generate.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -548,14 +548,15 @@ def ffn_or_attn_only(mod, fqn):
548548
precision == torch.float32
549549
), "int8_dynamic_activation_intx_weight requires fp32 precision"
550550

551-
# Build kernels in temp location, and load them in torch
552-
# This requires an ARM CPU
553-
from torchao.experimental.temp_build import temp_build_and_load_torchao_ops
554-
555-
temp_build_and_load_torchao_ops(
556-
cmake_lists_path=os.path.dirname(os.path.realpath(__file__))
557-
+ "/../../experimental"
558-
)
551+
try:
552+
torch.ops.torchao._pack_8bit_act_4bit_weight
553+
except:
554+
print(
555+
"Unable to load experimental torchao kernels. Performance will be slow."
556+
)
557+
print(
558+
"To install the kernels, run `USE_CPP=1 pip install .` from ao on a machine with an ARM CPU"
559+
)
559560

560561
# Quantize model
561562
_quant_args = quantization.split("-")

torchao/experimental/tests/test_embedding_xbit_quantizer.py

-40
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,17 @@
55
# LICENSE file in the root directory of this source tree.
66

77
import copy
8-
import glob
9-
import os
10-
import subprocess
11-
import sys
128
import tempfile
139
import unittest
1410

1511
import torch
1612

17-
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../..")))
1813
from torchao.experimental.quant_api import (
1914
IntxWeightEmbeddingQuantizer,
2015
_IntxWeightQuantizedEmbeddingFallback,
2116
)
2217

2318

24-
def cmake_build_torchao_ops(temp_build_dir):
25-
from distutils.sysconfig import get_python_lib
26-
27-
print("Building torchao ops for ATen target")
28-
cmake_prefix_path = get_python_lib()
29-
dir_path = os.path.dirname(os.path.realpath(__file__))
30-
subprocess.run(
31-
[
32-
"cmake",
33-
"-DCMAKE_PREFIX_PATH=" + cmake_prefix_path,
34-
"-DCMAKE_INSTALL_PREFIX=" + temp_build_dir.name,
35-
"-S " + dir_path + "/../",
36-
"-B " + temp_build_dir.name,
37-
]
38-
)
39-
subprocess.run(
40-
[
41-
"cmake",
42-
"--build",
43-
temp_build_dir.name,
44-
"-j 16",
45-
"--target install",
46-
"--config Release",
47-
]
48-
)
49-
50-
51-
temp_build_dir = tempfile.TemporaryDirectory()
52-
cmake_build_torchao_ops(temp_build_dir)
53-
libs = glob.glob(f"{temp_build_dir.name}/lib/libtorchao_ops_aten.*")
54-
libs = list(filter(lambda l: (l.endswith("so") or l.endswith("dylib")), libs))
55-
assert len(libs) == 1
56-
torch.ops.load_library(libs[0])
57-
58-
5919
class TestEmbeddingQuantizer(unittest.TestCase):
6020
def test_accuracy(self):
6121
group_size = 128

torchao/experimental/tests/test_linear_8bit_act_xbit_weight_quantizer.py

-40
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,17 @@
55
# LICENSE file in the root directory of this source tree.
66

77
import copy
8-
import glob
9-
import os
10-
import subprocess
11-
import sys
128
import tempfile
139
import unittest
1410

1511
import torch
1612

17-
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../..")))
1813
from torchao.experimental.quant_api import (
1914
Int8DynActIntxWeightLinearQuantizer,
2015
_Int8DynActIntxWeightQuantizedLinearFallback,
2116
)
2217

2318

24-
def cmake_build_torchao_ops(temp_build_dir):
25-
from distutils.sysconfig import get_python_lib
26-
27-
print("Building torchao ops for ATen target")
28-
cmake_prefix_path = get_python_lib()
29-
dir_path = os.path.dirname(os.path.realpath(__file__))
30-
subprocess.run(
31-
[
32-
"cmake",
33-
"-DCMAKE_PREFIX_PATH=" + cmake_prefix_path,
34-
"-DCMAKE_INSTALL_PREFIX=" + temp_build_dir.name,
35-
"-S " + dir_path + "/../",
36-
"-B " + temp_build_dir.name,
37-
]
38-
)
39-
subprocess.run(
40-
[
41-
"cmake",
42-
"--build",
43-
temp_build_dir.name,
44-
"-j 16",
45-
"--target install",
46-
"--config Release",
47-
]
48-
)
49-
50-
51-
temp_build_dir = tempfile.TemporaryDirectory()
52-
cmake_build_torchao_ops(temp_build_dir)
53-
libs = glob.glob(f"{temp_build_dir.name}/lib/libtorchao_ops_aten.*")
54-
libs = list(filter(lambda l: (l.endswith("so") or l.endswith("dylib")), libs))
55-
assert len(libs) == 1
56-
torch.ops.load_library(libs[0])
57-
58-
5919
class TestInt8DynActIntxWeightQuantizer(unittest.TestCase):
6020
def test_accuracy(self):
6121
group_size = 128

torchao/experimental/tests/test_linear_int8_dynamic_activation_intx_weight_subclass.py

-41
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,11 @@
55
# LICENSE file in the root directory of this source tree.
66

77
import copy
8-
import glob
9-
import os
10-
import subprocess
11-
import sys
128
import tempfile
139
import unittest
1410

1511
import torch
1612

17-
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../..")))
18-
1913
from torchao.experimental.quant_api import (
2014
_Int8DynActIntxWeightQuantizedLinearFallback,
2115
int8_dynamic_activation_intx_weight,
@@ -24,41 +18,6 @@
2418
from torchao.utils import unwrap_tensor_subclass
2519

2620

27-
def cmake_build_torchao_ops(temp_build_dir):
28-
from distutils.sysconfig import get_python_lib
29-
30-
print("Building torchao ops for ATen target")
31-
cmake_prefix_path = get_python_lib()
32-
dir_path = os.path.dirname(os.path.realpath(__file__))
33-
subprocess.run(
34-
[
35-
"cmake",
36-
"-DCMAKE_PREFIX_PATH=" + cmake_prefix_path,
37-
"-DCMAKE_INSTALL_PREFIX=" + temp_build_dir.name,
38-
"-S " + dir_path + "/../",
39-
"-B " + temp_build_dir.name,
40-
]
41-
)
42-
subprocess.run(
43-
[
44-
"cmake",
45-
"--build",
46-
temp_build_dir.name,
47-
"-j 16",
48-
"--target install",
49-
"--config Release",
50-
]
51-
)
52-
53-
54-
temp_build_dir = tempfile.TemporaryDirectory()
55-
cmake_build_torchao_ops(temp_build_dir)
56-
libs = glob.glob(f"{temp_build_dir.name}/lib/libtorchao_ops_aten.*")
57-
libs = list(filter(lambda l: (l.endswith("so") or l.endswith("dylib")), libs))
58-
assert len(libs) == 1
59-
torch.ops.load_library(libs[0])
60-
61-
6221
class TestInt8DynamicActivationIntxWeight(unittest.TestCase):
6322
def test_accuracy(self):
6423
group_size = 128

0 commit comments

Comments
 (0)