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

Add support for Qwen2VL #10361

Merged
merged 35 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c17546f
Barebone Qwen2VL LLM convertor
HimariO Sep 21, 2024
7c6f793
Add Qwen2VL cli entrypoint
HimariO Sep 22, 2024
b24bd89
[WIP] add qwen2vl arch
HimariO Sep 25, 2024
3541196
Verify m-rope output
HimariO Sep 29, 2024
9d389a0
Add vl-rope/2d-rope support for qwen2vl ViT
HimariO Sep 30, 2024
f661483
update qwen2vl cli tool
HimariO Oct 1, 2024
3c3691e
update 5D tensor op workaround
HimariO Oct 2, 2024
c13edfe
[WIP] qwen2vl vision model
HimariO Oct 10, 2024
7e9fc72
make batch and clip utils compatible with qwen2vl
HimariO Oct 18, 2024
bcd49f5
[WIP] create inference workflow, gguf convert script but fix
HimariO Oct 18, 2024
023f007
correcting vision-rope behavior, add the missing last layer back to ViT
HimariO Oct 20, 2024
3d19dd4
add arg parser to qwen2vl_surgery
HimariO Oct 20, 2024
53480d2
replace variable size array with vector
HimariO Oct 21, 2024
0882f57
cuda-gdb cmake preset
HimariO Oct 27, 2024
3237bb4
add fp32 mrope, vision rope kernel
HimariO Oct 28, 2024
201f704
add fp16 support for qwen2vl and m-rope
HimariO Oct 30, 2024
f1fa60f
add `GGML_ROPE_TYPE_MROPE`, `GGML_ROPE_TYPE_VISION`
HimariO Oct 30, 2024
241bb45
fix rope op mode switching, out dated func args
HimariO Nov 4, 2024
07553cf
update `llama_hparams`
HimariO Nov 10, 2024
fac0345
update to keep up stream changes
HimariO Nov 11, 2024
cbd08b4
resolve linter, test errors
HimariO Nov 29, 2024
6c39aa3
add makefile entry, update speical image padding token
HimariO Dec 7, 2024
ac2089c
add mrope unit test, fix few compiler warnings
HimariO Dec 7, 2024
12f17f7
rename `mrope` related function, params
HimariO Dec 7, 2024
3ba7664
minor updates on debug util, bug fixs
HimariO Dec 9, 2024
b24ab86
add `m-rope` testcase to `test-backend-ops`
HimariO Dec 9, 2024
d7edc55
Merge branch 'master' into qwen2-vl
HimariO Dec 11, 2024
9abb252
Apply suggestions from code review
HimariO Dec 13, 2024
c292bf1
Merge branch 'ggerganov:master' into qwen2-vl
HimariO Dec 13, 2024
e9748e4
fix traililng whitespce
HimariO Dec 13, 2024
ef7f74b
store `llama_hparams.rope_sections` with fixed size array
HimariO Dec 13, 2024
e2e9a6c
update position id tensor size check in GGML_OP_ROPE
HimariO Dec 13, 2024
a02a190
minor updates
HimariO Dec 13, 2024
19aba1d
update `ggml_backend_*_supports_op` of unsupported backends
HimariO Dec 13, 2024
f96909e
remote old `rope_section` compare operator
HimariO Dec 14, 2024
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
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ BUILD_TARGETS = \
llama-infill \
llama-llava-cli \
llama-minicpmv-cli\
llama-qwen2vl-cli\
llama-lookahead \
llama-lookup \
llama-lookup-create \
Expand Down Expand Up @@ -1404,6 +1405,14 @@ llama-minicpmv-cli: examples/llava/minicpmv-cli.cpp \
$(OBJ_ALL)
$(CXX) $(CXXFLAGS) $< $(filter-out %.h $<,$^) -o $@ $(LDFLAGS) -Wno-cast-qual

llama-qwen2vl-cli: examples/llava/qwen2vl-cli.cpp \
examples/llava/llava.cpp \
examples/llava/llava.h \
examples/llava/clip.cpp \
examples/llava/clip.h \
$(OBJ_ALL)
$(CXX) $(CXXFLAGS) $< $(filter-out %.h $<,$^) -o $@ $(LDFLAGS) -Wno-cast-qual

ifeq ($(UNAME_S),Darwin)
swift: examples/batched.swift
(cd examples/batched.swift; make build)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Instructions for adding support for new models: [HOWTO-add-model.md](docs/develo
- [x] [Mini CPM](https://huggingface.co/models?search=MiniCPM)
- [x] [Moondream](https://huggingface.co/vikhyatk/moondream2)
- [x] [Bunny](https://github.com/BAAI-DCAI/Bunny)
- [x] [Qwen2-VL](https://huggingface.co/collections/Qwen/qwen2-vl-66cee7455501d7126940800d)

</details>

Expand Down
23 changes: 23 additions & 0 deletions convert_hf_to_gguf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2001,6 +2001,29 @@ def set_gguf_parameters(self):
self.gguf_writer.add_rope_scaling_orig_ctx_len(self.hparams["rope_scaling"]["original_max_position_embeddings"])


@Model.register("Qwen2VLForConditionalGeneration")
class Qwen2VLModel(Model):
model_arch = gguf.MODEL_ARCH.QWEN2VL

def set_gguf_parameters(self):
super().set_gguf_parameters()
mrope_section = self.hparams["rope_scaling"]["mrope_section"]
mrope_section += [0] * max(0, 4 - len(mrope_section))
self.gguf_writer.add_rope_dimension_sections(mrope_section)

def set_vocab(self):
try:
self._set_vocab_sentencepiece()
except FileNotFoundError:
self._set_vocab_gpt2()

def get_tensors(self) -> Iterator[tuple[str, Tensor]]:
for name, data in super().get_tensors():
if name.startswith("visual."):
continue
yield name, data


@Model.register("Qwen2MoeForCausalLM")
class Qwen2MoeModel(Model):
model_arch = gguf.MODEL_ARCH.QWEN2MOE
Expand Down
7 changes: 7 additions & 0 deletions examples/llava/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@ set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME llama-minicpmv-cli)
install(TARGETS ${TARGET} RUNTIME)
target_link_libraries(${TARGET} PRIVATE common llava ${CMAKE_THREAD_LIBS_INIT})
target_compile_features(${TARGET} PRIVATE cxx_std_17)

set(TARGET llama-qwen2vl-cli)
add_executable(${TARGET} qwen2vl-cli.cpp)
set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME llama-qwen2vl-cli)
install(TARGETS ${TARGET} RUNTIME)
target_link_libraries(${TARGET} PRIVATE common llava ${CMAKE_THREAD_LIBS_INIT})
target_compile_features(${TARGET} PRIVATE cxx_std_17)
Loading
Loading