Skip to content

Commit ece8f4a

Browse files
pnbakawrykow
authored andcommitted
convert.py : Get rope scale from HuggingFace models (ggml-org#2772)
* Get rope scale from HF models * Save rope scale only for linear scaling * Rewrite for clarity
1 parent 5274318 commit ece8f4a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

convert.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class Params:
105105
f_norm_eps: float
106106

107107
f_rope_freq_base: Optional[float] = None
108+
f_rope_scale: Optional[float] = None
108109

109110
ftype: Optional[GGMLFileType] = None
110111

@@ -169,6 +170,11 @@ def loadHFTransformerJson(model: 'LazyModel', config_path: 'Path') -> 'Params':
169170
f_norm_eps = config["rms_norm_eps"]
170171
f_rope_freq_base = config["rope_theta"] if "rope_theta" in config else None
171172

173+
if "rope_scaling" in config and config["rope_scaling"].get("type") == "linear":
174+
f_rope_scale = config["rope_scaling"].get("factor")
175+
else:
176+
f_rope_scale = None
177+
172178
n_mult = Params.find_n_mult(n_ff, n_embd)
173179

174180
if "max_sequence_length" in config:
@@ -190,6 +196,7 @@ def loadHFTransformerJson(model: 'LazyModel', config_path: 'Path') -> 'Params':
190196
n_head_kv = n_head_kv,
191197
f_norm_eps = f_norm_eps,
192198
f_rope_freq_base = f_rope_freq_base,
199+
f_rope_scale = f_rope_scale,
193200
)
194201

195202
# LLaMA v2 70B params.json
@@ -773,6 +780,9 @@ def add_meta_arch(self, params: Params) -> None:
773780
if params.f_rope_freq_base:
774781
self.gguf.add_rope_freq_base(params.f_rope_freq_base)
775782

783+
if params.f_rope_scale:
784+
self.gguf.add_rope_scale_linear(params.f_rope_scale)
785+
776786
if params.ftype:
777787
self.gguf.add_file_type(params.ftype)
778788

0 commit comments

Comments
 (0)