Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove temp build files from torchao #1551

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions torchao/_models/llama/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,14 +548,15 @@ def ffn_or_attn_only(mod, fqn):
precision == torch.float32
), "int8_dynamic_activation_intx_weight requires fp32 precision"

# Build kernels in temp location, and load them in torch
# This requires an ARM CPU
from torchao.experimental.temp_build import temp_build_and_load_torchao_ops

temp_build_and_load_torchao_ops(
cmake_lists_path=os.path.dirname(os.path.realpath(__file__))
+ "/../../experimental"
)
try:
torch.ops.torchao._pack_8bit_act_4bit_weight
except:
print(
"Unable to load experimental torchao kernels. Performance will be slow."
)
print(
"To install the kernels, run `USE_CPP=1 pip install .` from ao on a machine with an ARM CPU"
Copy link
Contributor

@jerryzh168 jerryzh168 Jan 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this included in the default build as well? i.e. does installing torchao nightly include this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I quickly glanced and it does not look like the default nightly build for M1 mac defines USE_CPP=1, although adding it should be pretty simple.

)

# Quantize model
_quant_args = quantization.split("-")
Expand Down
40 changes: 0 additions & 40 deletions torchao/experimental/tests/test_embedding_xbit_quantizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,17 @@
# LICENSE file in the root directory of this source tree.

import copy
import glob
import os
import subprocess
import sys
import tempfile
import unittest

import torch

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../..")))
from torchao.experimental.quant_api import (
IntxWeightEmbeddingQuantizer,
_IntxWeightQuantizedEmbeddingFallback,
)


def cmake_build_torchao_ops(temp_build_dir):
from distutils.sysconfig import get_python_lib

print("Building torchao ops for ATen target")
cmake_prefix_path = get_python_lib()
dir_path = os.path.dirname(os.path.realpath(__file__))
subprocess.run(
[
"cmake",
"-DCMAKE_PREFIX_PATH=" + cmake_prefix_path,
"-DCMAKE_INSTALL_PREFIX=" + temp_build_dir.name,
"-S " + dir_path + "/../",
"-B " + temp_build_dir.name,
]
)
subprocess.run(
[
"cmake",
"--build",
temp_build_dir.name,
"-j 16",
"--target install",
"--config Release",
]
)


temp_build_dir = tempfile.TemporaryDirectory()
cmake_build_torchao_ops(temp_build_dir)
libs = glob.glob(f"{temp_build_dir.name}/lib/libtorchao_ops_aten.*")
libs = list(filter(lambda l: (l.endswith("so") or l.endswith("dylib")), libs))
assert len(libs) == 1
torch.ops.load_library(libs[0])


class TestEmbeddingQuantizer(unittest.TestCase):
def test_accuracy(self):
group_size = 128
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,17 @@
# LICENSE file in the root directory of this source tree.

import copy
import glob
import os
import subprocess
import sys
import tempfile
import unittest

import torch

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../..")))
from torchao.experimental.quant_api import (
Int8DynActIntxWeightLinearQuantizer,
_Int8DynActIntxWeightQuantizedLinearFallback,
)


def cmake_build_torchao_ops(temp_build_dir):
from distutils.sysconfig import get_python_lib

print("Building torchao ops for ATen target")
cmake_prefix_path = get_python_lib()
dir_path = os.path.dirname(os.path.realpath(__file__))
subprocess.run(
[
"cmake",
"-DCMAKE_PREFIX_PATH=" + cmake_prefix_path,
"-DCMAKE_INSTALL_PREFIX=" + temp_build_dir.name,
"-S " + dir_path + "/../",
"-B " + temp_build_dir.name,
]
)
subprocess.run(
[
"cmake",
"--build",
temp_build_dir.name,
"-j 16",
"--target install",
"--config Release",
]
)


temp_build_dir = tempfile.TemporaryDirectory()
cmake_build_torchao_ops(temp_build_dir)
libs = glob.glob(f"{temp_build_dir.name}/lib/libtorchao_ops_aten.*")
libs = list(filter(lambda l: (l.endswith("so") or l.endswith("dylib")), libs))
assert len(libs) == 1
torch.ops.load_library(libs[0])


class TestInt8DynActIntxWeightQuantizer(unittest.TestCase):
def test_accuracy(self):
group_size = 128
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@
# LICENSE file in the root directory of this source tree.

import copy
import glob
import os
import subprocess
import sys
import tempfile
import unittest

import torch

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../..")))

from torchao.experimental.quant_api import (
_Int8DynActIntxWeightQuantizedLinearFallback,
int8_dynamic_activation_intx_weight,
Expand All @@ -24,41 +18,6 @@
from torchao.utils import unwrap_tensor_subclass


def cmake_build_torchao_ops(temp_build_dir):
from distutils.sysconfig import get_python_lib

print("Building torchao ops for ATen target")
cmake_prefix_path = get_python_lib()
dir_path = os.path.dirname(os.path.realpath(__file__))
subprocess.run(
[
"cmake",
"-DCMAKE_PREFIX_PATH=" + cmake_prefix_path,
"-DCMAKE_INSTALL_PREFIX=" + temp_build_dir.name,
"-S " + dir_path + "/../",
"-B " + temp_build_dir.name,
]
)
subprocess.run(
[
"cmake",
"--build",
temp_build_dir.name,
"-j 16",
"--target install",
"--config Release",
]
)


temp_build_dir = tempfile.TemporaryDirectory()
cmake_build_torchao_ops(temp_build_dir)
libs = glob.glob(f"{temp_build_dir.name}/lib/libtorchao_ops_aten.*")
libs = list(filter(lambda l: (l.endswith("so") or l.endswith("dylib")), libs))
assert len(libs) == 1
torch.ops.load_library(libs[0])


class TestInt8DynamicActivationIntxWeight(unittest.TestCase):
def test_accuracy(self):
group_size = 128
Expand Down
Loading