Skip to content

Commit d0f77b1

Browse files
authored
convert.py : try to determine n_ctx automatically for CodeLlama (#2770)
1 parent 0d3094f commit d0f77b1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

convert.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,23 @@ def loadOriginalParamsJson(model: 'LazyModel', config_path: 'Path') -> 'Params':
200200
n_embd = config["dim"]
201201
n_layer = config["n_layers"]
202202
n_mult = config["multiple_of"]
203-
n_ctx = 2048 if config["norm_eps"] == 1e-06 else 4096 # hack to determine LLaMA v1 vs v2
204203
n_ff = -1
205204
n_head = config["n_heads"]
206205
n_head_kv = config["n_kv_heads"] if "n_kv_heads" in config else n_head
207206
f_norm_eps = config["norm_eps"]
208207
f_rope_freq_base = config["rope_theta"] if "rope_theta" in config else None
209208

209+
# hack to determine LLaMA v1 vs v2 vs CodeLlama
210+
if f_rope_freq_base and f_rope_freq_base == 1000000:
211+
# CodeLlama
212+
n_ctx = 16384
213+
elif config["norm_eps"] == 1e-05:
214+
# LLaMA v2
215+
n_ctx = 4096
216+
else:
217+
# LLaMA v1
218+
n_ctx = 2048
219+
210220
if n_vocab == -1:
211221
n_vocab = model["tok_embeddings.weight"].shape[0]
212222

0 commit comments

Comments
 (0)