Skip to content

Commit 1d8dea5

Browse files
committed
resolve linter, test errors
1 parent 5235dbc commit 1d8dea5

File tree

4 files changed

+17
-21
lines changed

4 files changed

+17
-21
lines changed

convert_hf_to_gguf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1991,7 +1991,7 @@ def set_vocab(self):
19911991
self._set_vocab_sentencepiece()
19921992
except FileNotFoundError:
19931993
self._set_vocab_gpt2()
1994-
1994+
19951995
def get_tensors(self) -> Iterator[tuple[str, Tensor]]:
19961996
for name, data in super().get_tensors():
19971997
if name.startswith("visual."):

examples/llava/qwen2_vl_surgery.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import argparse
2-
import glob
3-
import os
4-
from typing import Any, Dict
2+
from typing import Dict
53

64
import torch
5+
import numpy as np
76
from gguf import *
87
from transformers import (
9-
Qwen2VLForConditionalGeneration,
8+
Qwen2VLForConditionalGeneration,
109
Qwen2VLProcessor,
1110
AutoProcessor,
1211
Qwen2VLConfig
@@ -44,7 +43,7 @@ def find_vision_tensors(qwen2vl, dtype) -> Dict[str, np.ndarray]:
4443
else: # bias
4544
c3 = ten.shape[0]
4645
assert c3 % 3 == 0
47-
c = c3//3
46+
c = c3 // 3
4847
wq = ten[:c]
4948
wk = ten[c: c * 2]
5049
wv = ten[c * 2:]
@@ -68,7 +67,7 @@ def find_vision_tensors(qwen2vl, dtype) -> Dict[str, np.ndarray]:
6867
tensor_map["v.patch_embd.weight.1"] = ten[:, :, 1, ...]
6968
else:
7069
tensor_map[to_gguf_name(f"vision_model.{name}")] = ten
71-
70+
7271
for new_name, ten in tensor_map.items():
7372
if ten.ndim <= 1 or new_name.endswith("_norm.weight"):
7473
tensor_map[new_name] = ten.astype(np.float32)
@@ -89,16 +88,14 @@ def main(args):
8988
ftype = 1
9089
else:
9190
raise ValueError()
92-
91+
9392
model_name = args.model_name
9493
print("model_name: ", model_name)
9594
qwen2vl = Qwen2VLForConditionalGeneration.from_pretrained(
9695
model_name, torch_dtype=dtype, device_map="cpu"
9796
)
98-
cfg: Qwen2VLConfig = qwen2vl.config
97+
cfg: Qwen2VLConfig = qwen2vl.config # type: ignore[reportAssignmentType]
9998
vcfg = cfg.vision_config
100-
rope_cfg = cfg.rope_scaling
101-
10299

103100
fname_out = "qwen2vl-vision.gguf"
104101
fout = GGUFWriter(path=fname_out, arch="clip")
@@ -125,23 +122,22 @@ def main(args):
125122
fout.add_tensor(name, data)
126123

127124
fout.add_uint32("clip.vision.patch_size", vcfg.patch_size)
128-
fout.add_uint32("clip.vision.image_size", 14*40) # some reasonable size that is divable by (14*2)
125+
fout.add_uint32("clip.vision.image_size", 14 * 40) # some reasonable size that is divable by (14*2)
129126
fout.add_uint32(k(KEY_EMBEDDING_LENGTH, VISION), vcfg.embed_dim)
130127
fout.add_uint32("clip.vision.projection_dim", vcfg.hidden_size)
131128
fout.add_uint32(k(KEY_ATTENTION_HEAD_COUNT, VISION), vcfg.num_heads)
132129
fout.add_float32(k(KEY_ATTENTION_LAYERNORM_EPS, VISION), 1e-6)
133130
fout.add_uint32(k(KEY_BLOCK_COUNT, VISION), vcfg.depth)
134-
fout.add_uint32(k(KEY_FEED_FORWARD_LENGTH, VISION), 0) # BUG: not sure what this does
131+
fout.add_uint32(k(KEY_FEED_FORWARD_LENGTH, VISION), 0) # not sure what this does, put 0 here as a placeholder
135132
fout.add_name(model_name)
136133
"""
137-
HACK: Since vision rope related parameter aren't stored in the `Qwen2VLConfig,
134+
HACK: Since vision rope related parameter aren't stored in the `Qwen2VLConfig,
138135
it will be hardcoded in the `clip_image_build_graph` from `clip.cpp`.
139136
"""
140137

141138
processor: Qwen2VLProcessor = AutoProcessor.from_pretrained(model_name)
142-
# breakpoint()
143-
fout.add_array("clip.vision.image_mean", processor.image_processor.image_mean)
144-
fout.add_array("clip.vision.image_std", processor.image_processor.image_std)
139+
fout.add_array("clip.vision.image_mean", processor.image_processor.image_mean) # type: ignore[reportAttributeAccessIssue]
140+
fout.add_array("clip.vision.image_std", processor.image_processor.image_std) # type: ignore[reportAttributeAccessIssue]
145141

146142
fout.write_header_to_file()
147143
fout.write_kv_data_to_file()
@@ -154,4 +150,4 @@ def main(args):
154150
parser.add_argument("model_name", nargs='?', default="Qwen/Qwen2-VL-2B-Instruct")
155151
parser.add_argument("--data_type", nargs='?', choices=['fp32', 'fp16'], default="fp32")
156152
args = parser.parse_args()
157-
main(args)
153+
main(args)

ggml/include/ggml.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@
238238
#define GGML_EXIT_ABORTED 1
239239

240240
#define GGML_ROPE_TYPE_NEOX 2
241-
#define GGML_ROPE_TYPE_MROPE 4
242-
#define GGML_ROPE_TYPE_VISION 12
241+
#define GGML_ROPE_TYPE_MROPE 8
242+
#define GGML_ROPE_TYPE_VISION 24
243243

244244
#define GGUF_MAGIC "GGUF"
245245

gguf-py/gguf/gguf_writer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ def add_pooling_type(self, value: PoolingType) -> None:
720720

721721
def add_rope_dimension_count(self, count: int) -> None:
722722
self.add_uint32(Keys.Rope.DIMENSION_COUNT.format(arch=self.arch), count)
723-
723+
724724
def add_rope_dimension_sections(self, dims: Sequence[int]) -> None:
725725
self.add_array(Keys.Rope.DIMENSION_SECTIONS.format(arch=self.arch), dims)
726726

0 commit comments

Comments
 (0)