|
| 1 | +# Copyright (c) Qualcomm Innovation Center, Inc. |
| 2 | +# All rights reserved |
| 3 | +# |
| 4 | +# This source code is licensed under the BSD-style license found in the |
| 5 | +# LICENSE file in the root directory of this source tree. |
| 6 | + |
| 7 | + |
| 8 | +def convert_configs(config): |
| 9 | + # HF config keys are different from Llama configs. |
| 10 | + # Convert the config keys to align with Llama. |
| 11 | + if hasattr(config, "hidden_size"): |
| 12 | + config.dim = config.hidden_size |
| 13 | + delattr(config, "hidden_size") |
| 14 | + |
| 15 | + if hasattr(config, "num_attention_heads"): |
| 16 | + config.n_heads = config.num_attention_heads |
| 17 | + delattr(config, "num_attention_heads") |
| 18 | + |
| 19 | + if hasattr(config, "num_key_value_heads"): |
| 20 | + config.n_kv_heads = config.num_key_value_heads |
| 21 | + delattr(config, "num_key_value_heads") |
| 22 | + |
| 23 | + if hasattr(config, "rms_norm_eps"): |
| 24 | + config.norm_eps = config.rms_norm_eps |
| 25 | + delattr(config, "rms_norm_eps") |
| 26 | + |
| 27 | + if hasattr(config, "rope_theta"): |
| 28 | + config.rope_freq_base = config.rope_theta |
| 29 | + delattr(config, "rope_theta") |
| 30 | + |
| 31 | + if hasattr(config, "num_hidden_layers"): |
| 32 | + config.n_layers = config.num_hidden_layers |
| 33 | + delattr(config, "num_hidden_layers") |
| 34 | + |
| 35 | + if hasattr(config, "intermediate_size"): |
| 36 | + config.hidden_dim = config.intermediate_size |
| 37 | + delattr(config, "intermediate_size") |
| 38 | + |
| 39 | + if hasattr(config, "rope_scaling"): |
| 40 | + config.use_scaled_rope = config.rope_scaling |
| 41 | + # Use default value of precompute_freq_cis |
| 42 | + if not hasattr(config, "rope_scale_factor"): |
| 43 | + config.rope_scale_factor = 4 |
| 44 | + |
| 45 | + return config |
0 commit comments