Skip to content

Commit 897788e

Browse files
committed
[llava] Use huggingface LLaVA instead of depending on third-party/LLaVa
Currently we depend on third-party/LLaVA for llava model definition. This is hard to use because we have to pull LLaVA in as a git submodule and install from there. It also breaks a lot of dependency assumptions. This PR removes `third-party/LLaVA`, in favor of huggingface llava model definition. ghstack-source-id: fafdedd Pull Request resolved: #4687
1 parent 2117c1a commit 897788e

File tree

6 files changed

+186
-174
lines changed

6 files changed

+186
-174
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
[submodule "backends/xnnpack/third-party/pthreadpool"]
2929
path = backends/xnnpack/third-party/pthreadpool
3030
url = https://github.com/Maratyszcza/pthreadpool.git
31-
[submodule "examples/third-party/LLaVA"]
32-
path = examples/third-party/LLaVA
33-
url = https://github.com/haotian-liu/LLaVA.git
3431
[submodule "examples/third-party/fbjni"]
3532
path = examples/third-party/fbjni
3633
url = https://github.com/facebookincubator/fbjni.git

examples/models/llava/export_llava.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -167,24 +167,7 @@ def export_token_embedding(llava, prompt):
167167
return token_embedding_ep
168168

169169

170-
def main():
171-
parser = ArgumentParser()
172-
parser.add_argument(
173-
"--use-sdpa-with-kv-cache",
174-
default=True,
175-
action=BooleanOptionalAction,
176-
help="Use sdpa_with_kv_cache custom op in LLava text model.",
177-
)
178-
parser.add_argument(
179-
"--pte-name",
180-
default="llava_combined_xnnpack.pte",
181-
help="Name of the exported ExecuTorch program.",
182-
)
183-
args = parser.parse_args()
184-
logging.info(
185-
f"Exporting Llava model to ExecuTorch with sdpa_with_kv_cache: {args.use_sdpa_with_kv_cache}"
186-
)
187-
llava_model = LlavaModel(use_sdpa_with_kv_cache_op=args.use_sdpa_with_kv_cache)
170+
def export_all(llava_model: LlavaModel):
188171
llava = llava_model.get_eager_model()
189172

190173
(
@@ -226,6 +209,29 @@ def main():
226209
)
227210

228211
executorch_program = lowered_and_edge.to_executorch()
212+
return executorch_program
213+
214+
215+
def main():
216+
parser = ArgumentParser()
217+
parser.add_argument(
218+
"--use-sdpa-with-kv-cache",
219+
default=True,
220+
action=BooleanOptionalAction,
221+
help="Use sdpa_with_kv_cache custom op in LLava text model.",
222+
)
223+
parser.add_argument(
224+
"--pte-name",
225+
default="llava_combined_xnnpack.pte",
226+
help="Name of the exported ExecuTorch program.",
227+
)
228+
args = parser.parse_args()
229+
logging.info(
230+
f"Exporting Llava model to ExecuTorch with sdpa_with_kv_cache: {args.use_sdpa_with_kv_cache}"
231+
)
232+
llava_model = LlavaModel(use_sdpa_with_kv_cache_op=args.use_sdpa_with_kv_cache)
233+
234+
executorch_program = export_all(llava_model)
229235

230236
with open(args.pte_name, "wb") as f:
231237
executorch_program.write_to_file(f)

examples/models/llava/install_requirements.sh

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,7 @@
66
# LICENSE file in the root directory of this source tree.
77

88
set -x
9-
OS=$(uname)
109

11-
# install llava from the submodule. We can't do pip install llava because it is packaged incorrectly.
12-
if [[ $OS != "Darwin" ]];
13-
then
14-
#This doesn't work for macos, on python 3.12, because torch 2.1.2 is missing.
15-
pip install --force-reinstall -e examples/third-party/LLaVA
16-
else
17-
# manually install dependencies
18-
pip install tokenizers==0.15.1 sentencepiece==0.1.99 \
19-
shortuuid accelerate==0.21.0 peft \
20-
pydantic markdown2[all] scikit-learn==1.2.2 \
21-
requests httpx==0.24.0 uvicorn fastapi \
22-
einops==0.6.1 einops-exts==0.0.4 timm==0.6.13
23-
24-
pip install --force-reinstall -e examples/third-party/LLaVA --no-deps
25-
fi
26-
27-
# not included in the pip install package, but needed in llava
28-
pip install protobuf
29-
30-
# bitsandbytes depends on numpy 1.x, which is not compatible with numpy 2.x.
31-
# Reinstall bitsandbytes to make it compatible.
32-
pip install bitsandbytes -I
33-
34-
# The deps of llava can have different versions than deps of ExecuTorch.
35-
# For example, torch version required from llava is older than ExecuTorch.
36-
# To make both work, recover ExecuTorch's original dependencies by rerunning
37-
# the install_requirements.sh. Notice this won't install executorch.
38-
bash -x ./install_requirements.sh --pybind xnnpack
39-
40-
# Newer transformer (4.38) will give TypeError: LlavaLlamaForCausalLM.forward() got an unexpected keyword argument 'cache_position'
41-
pip install timm==0.6.13
42-
pip install transformers==4.37.2
10+
pip install transformers
4311

4412
pip list

0 commit comments

Comments
 (0)