Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

Commit 30f70b8

Browse files
authored
Merge branch 'main' into lessw2020/prefill
2 parents ab9a24d + 6fae164 commit 30f70b8

File tree

7 files changed

+62
-50
lines changed

7 files changed

+62
-50
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ __pycache__/
66
# C extensions
77
*.so
88

9+
.vscode
910
.model-artifacts/
1011
.venv
1112
.torchchat
@@ -15,6 +16,7 @@ build/android/*
1516
et-build/*
1617
runner-et/cmake-out/*
1718
runner-aoti/cmake-out/*
19+
cmake-out/
1820

1921
# pte files
2022
*.pte
@@ -24,3 +26,7 @@ system_info.txt
2426

2527
# intermediate system file
2628
.DS_Store
29+
30+
# build artifacts
31+
checkpoints/
32+
exportedModels/

install/install_requirements.sh

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ PYTORCH_NIGHTLY_VERSION=dev20240814
5252
# Nightly version for torchvision
5353
VISION_NIGHTLY_VERSION=dev20240814
5454

55-
# Nightly version for torchao
56-
AO_NIGHTLY_VERSION=dev20240905
57-
5855
# Nightly version for torchtune
5956
TUNE_NIGHTLY_VERSION=dev20240910
6057

@@ -79,10 +76,6 @@ fi
7976
REQUIREMENTS_TO_INSTALL=(
8077
torch=="2.5.0.${PYTORCH_NIGHTLY_VERSION}"
8178
torchvision=="0.20.0.${VISION_NIGHTLY_VERSION}"
82-
)
83-
84-
LINUX_REQUIREMENTS_TO_INSTALL=(
85-
torchao=="0.5.0.${AO_NIGHTLY_VERSION}"
8679
torchtune=="0.3.0.${TUNE_NIGHTLY_VERSION}"
8780
)
8881

@@ -94,27 +87,10 @@ LINUX_REQUIREMENTS_TO_INSTALL=(
9487
"${REQUIREMENTS_TO_INSTALL[@]}"
9588
)
9689

97-
PLATFORM=$(uname -s)
98-
99-
# Install torchtune and torchao requirements for Linux systems using nightly.
100-
# For non-Linux systems (e.g., macOS), install torchao from GitHub since nightly
101-
# build doesn't have macOS build.
102-
# TODO: Remove this and install nightly build, once it supports macOS
103-
if [ "$PLATFORM" == "Linux" ];
104-
then
105-
(
106-
set -x
107-
$PIP_EXECUTABLE install --pre --extra-index-url "${TORCH_NIGHTLY_URL}" --no-cache-dir \
108-
"${LINUX_REQUIREMENTS_TO_INSTALL[@]}"
109-
)
110-
else
111-
# For torchao need to install from github since nightly build doesn't have macos build.
112-
# TODO: Remove this and install nightly build, once it supports macos
113-
(
114-
set -x
115-
$PIP_EXECUTABLE install git+https://github.com/pytorch/ao.git@e11201a62669f582d81cdb33e031a07fb8dfc4f3
116-
)
117-
fi
90+
(
91+
set -x
92+
$PIP_EXECUTABLE install torchao=="0.5.0"
93+
)
11894

11995
if [[ -x "$(command -v nvidia-smi)" ]]; then
12096
(

torchchat/cli/builder.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,8 @@
3535
from torchchat.utils.measure_time import measure_time
3636
from torchchat.utils.quantize import quantize_model
3737

38-
# bypass the import issue before torchao is ready on macos
39-
try:
40-
from torchtune.models.convert_weights import meta_to_tune
41-
except:
42-
pass
38+
from torchtune.models.convert_weights import meta_to_tune
39+
4340

4441

4542

torchchat/edge/docs/Android.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ In your app working directory (for example executorch/examples/demo-apps/android
3737
copy the AAR to your app libs:
3838
```bash
3939
mkdir -p app/libs
40-
cp ${TORCHCHAT_ROOT}/android/torchchat/app/libs/executorch.aar ${YOUR_APP_ROOT}/app/libs/executorch.jar
40+
cp ${TORCHCHAT_ROOT}/android/torchchat/app/libs/executorch.aar ${YOUR_APP_ROOT}/app/libs/executorch.aar
4141
```
4242

43-
In your Java app, add the jar file path to your gradle build rule.
43+
In your Java app, add the aar file path to your gradle build rule.
4444
```
4545
# app/build.grardle.kts
4646
dependencies {

torchchat/generate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ def chat(
739739
)
740740
for i in range(num_samples):
741741
device_sync(device=self.builder_args.device)
742-
if i >= 0 and generator_args.chat_mode:
742+
if generator_args.chat_mode:
743743
prompt = input("User: ")
744744
if prompt == "/bye":
745745
print("Exiting Chat.\n")
@@ -784,7 +784,6 @@ def chat(
784784
)
785785
break
786786

787-
if generator_args.chat_mode and i >= 0:
788787
print("Model: ", end="")
789788

790789
buffer = []
@@ -927,7 +926,8 @@ def callback(x, *, done_generating=False):
927926
\nAverage tokens/sec (next tokens): {torch.mean(torch.tensor(aggregate_metrics['next_tokens_per_sec'])).item():.2f} \n\
928927
"
929928
)
930-
print(f"Memory used: {torch.cuda.max_memory_reserved() / 1e9:.02f} GB")
929+
if torch.cuda.is_available():
930+
print(f"Memory used: {torch.cuda.max_memory_reserved() / 1e9:.02f} GB")
931931

932932

933933
def main(args):

torchchat/model.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,9 @@
3030

3131
from torchchat.utils.build_utils import find_multiple, get_precision
3232

33-
# bypass the import issue, if any
34-
# TODO: remove this once the torchao is ready on macos
35-
try:
36-
from torchtune.models.flamingo import flamingo_decoder, flamingo_vision_encoder
37-
from torchtune.modules.model_fusion import DeepFusionModel
38-
from torchtune.models.llama3_1._component_builders import llama3_1 as llama3_1_builder
39-
except:
40-
pass
33+
from torchtune.models.flamingo import flamingo_decoder, flamingo_vision_encoder
34+
from torchtune.modules.model_fusion import DeepFusionModel
35+
from torchtune.models.llama3_1._component_builders import llama3_1 as llama3_1_builder
4136

4237
config_path = Path(f"{str(Path(__file__).parent)}/model_params")
4338

torchchat/utils/scripts/install_utils.sh

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

88
set -ex pipefail
99

10+
if [ -z "$TORCHCHAT_ROOT" ]; then
11+
echo "Defaulting TORCHCHAT_ROOT to $PWD since it is unset."
12+
TORCHCHAT_ROOT=$PWD
13+
fi
14+
1015
install_pip_dependencies() {
1116
echo "Intalling common pip packages"
1217
pip3 install wheel "cmake>=3.19" ninja zstd
@@ -20,21 +25,54 @@ function find_cmake_prefix_path() {
2025
MY_CMAKE_PREFIX_PATH=$path
2126
}
2227

23-
clone_executorch() {
24-
echo "Cloning executorch to ${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/src"
25-
rm -rf ${TORCHCHAT_ROOT}/${ET_BUILD_DIR}
28+
clone_executorch_internal() {
29+
rm -rf ${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/src
30+
2631
mkdir -p ${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/src
2732
pushd ${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/src
2833
git clone https://github.com/pytorch/executorch.git
2934
cd executorch
3035
git checkout $(cat ${TORCHCHAT_ROOT}/install/.pins/et-pin.txt)
31-
echo "Install executorch: submodule update"
36+
echo "Install ExecuTorch: submodule update"
3237
git submodule sync
3338
git submodule update --init
3439

3540
popd
3641
}
3742

43+
clone_executorch() {
44+
echo "Cloning ExecuTorch to ${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/src"
45+
46+
# Check if executorch is already cloned and has the correct version
47+
if [ -d "${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/src/executorch" ]; then
48+
pushd ${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/src/executorch
49+
50+
# Check if the repo is clean
51+
git_status=$(git status --porcelain)
52+
if [ -n "$git_status" ]; then
53+
echo "ExecuTorch repo is not clean. Removing and recloning."
54+
popd
55+
clone_executorch_internal
56+
return
57+
fi
58+
59+
# Check if the version is the same
60+
current_version=$(git rev-parse HEAD)
61+
desired_version=$(cat ${TORCHCHAT_ROOT}/install/.pins/et-pin.txt)
62+
63+
if [ "$current_version" == "$desired_version" ]; then
64+
echo "ExecuTorch is already cloned with the correct version. Skipping clone."
65+
popd
66+
return
67+
fi
68+
69+
echo "ExecuTorch is already cloned but has the wrong version. Removing and recloning."
70+
popd
71+
fi
72+
73+
clone_executorch_internal
74+
}
75+
3876
install_executorch_python_libs() {
3977
if [ ! -d "${TORCHCHAT_ROOT}/${ET_BUILD_DIR}" ]; then
4078
echo "Directory ${TORCHCHAT_ROOT}/${ET_BUILD_DIR} does not exist."

0 commit comments

Comments
 (0)