| 1 | 1 | // the hash can be obtained from command line e.g. via: MODEL=path_to_model; python -c "import json, hashlib, sys; print(hashlib.sha256(json.load(open('"$MODEL"/tokenizer_config.json'))['chat_template'].strip().encode()).hexdigest())" |
| 2 | 2 | // note that chat templates must be trimmed to match the llama.cpp metadata value |
| 3 | 3 | const derivations = { |
| 4 | 4 | // Meta |
| 5 | 5 | '93c0e9aa3629bbd77e68dbc0f5621f6e6b23aa8d74b932595cdb8d64684526d7e10ca381b1ccc5cf9db52e371f3b6651576caee0a630b452e2816b2d404d4b65': { |
| 6 | 6 | // Meta-Llama-3.1-8B-Instruct |
| 7 | 7 | // Meta-Llama-3.1-70B-Instruct |
| 8 | 8 | context: 'Llama 3 Instruct', |
| 9 | | - instruct: 'Llama 3 Instruct', |
| 9 | + , |
| 10 | | - }, |
| 10 | + '5816fce10444e03c2e9ee1ef8a4a1ea61ae7e69e438613f3b17b69d0426223a4': |
| 11 | | - 'd82792f95932f1c9cef5c4bd992f171225e3bf8c7b609b4557c9e1ec96be819f': { |
| 12 | 11 | // Llama-3.2-1B-Instruct |
| 13 | 12 | // Llama-3.2-3B-Instruct |
| 14 | 13 | context: 'Llama 3 Instruct', |
| 15 | | - instruct: 'Llama 3 Instruct', |
| 14 | + , |
| 16 | | - }, |
| 15 | + '73e87b1667d87ab7d7b579107f01151b29ce7f3ccdd1018fdc397e78be76219d': |
| 16 | + // Nemotron 70B |
| 17 | + 'Llama 3 Instruct' |
| 18 | + , |
| 17 | 19 | |
| 18 | 20 | // Mistral |
| 19 | 21 | // Mistral Reference: https://github.com/mistralai/mistral-common |
| 20 | 22 | 'cafb64e0e9e5fd2503054b3479593fae39cbdfd52338ce8af9bb4664a8eb05bde16746b40344d6c5b5265988e0328a0bf7277be86f1c335156eae07e29c82826': { |
| 21 | 23 | // Mistral-Small-Instruct-2409 |
| 22 | 24 | // Mistral-Large-Instruct-2407 |
| 23 | 25 | context: 'Mistral V2 & V3', |
| 24 | | - instruct: 'Mistral V2 & V3', |
| 26 | + , |
| 25 | | - }, |
| 27 | + '3c4ad5fa60dd8c7ccdf82fa4225864c903e107728fcaf859fa6052cb80c92ee9': |
| 26 | | - '3c4ad5fa60dd8c7ccdf82fa4225864c903e107728fcaf859fa6052cb80c92ee9': { |
| 27 | 28 | // Mistral-Large-Instruct-2411 |
| 28 | 29 | context: 'Mistral V7', // https://huggingface.co/mistralai/Mistral-Large-Instruct-2411 |
| 29 | | - instruct: 'Mistral V7', |
| 30 | + , |
| 30 | | - }, |
| 31 | + 'e4676cb56dffea7782fd3e2b577cfaf1e123537e6ef49b3ec7caa6c095c62272': |
| 31 | | - 'e7deee034838db2bfc7487788a3013d8a307ab69f72f3c54a85f06fd76007d4e': { |
| 32 | 32 | // Mistral-Nemo-Instruct-2407 |
| 33 | 33 | context: 'Mistral V3-Tekken', |
| 34 | | - instruct: 'Mistral V3-Tekken', |
| 34 | + , |
| 35 | | - }, |
| 35 | + '26a59556925c987317ce5291811ba3b7f32ec4c647c400c6cc7e3a9993007ba7': |
| 36 | | - '26a59556925c987317ce5291811ba3b7f32ec4c647c400c6cc7e3a9993007ba7': { |
| 37 | 36 | // Mistral-7B-Instruct-v0.3 |
| 38 | 37 | context: 'Mistral V2 & V3', |
| 39 | | - instruct: 'Mistral V2 & V3', |
| 38 | + , |
| 40 | | - }, |
| 41 | 39 | |
| 42 | 40 | // Gemma |
| 43 | 41 | 'ecd6ae513fe103f0eb62e8ab5bfa8d0fe45c1074fa398b089c93a7e70c15cfd6': { |
| 44 | 42 | // gemma-2-9b-it |
| 45 | 43 | // gemma-2-27b-it |
| 46 | 44 | context: 'Gemma 2', |
| 47 | | - instruct: 'Gemma 2', |
| 45 | + , |
| 48 | | - }, |
| 49 | 46 | |
| 50 | 47 | // Cohere |
| 51 | 48 | '3b54f5c219ae1caa5c0bb2cdc7c001863ca6807cf888e4240e8739fa7eb9e02e': { |
| 52 | 49 | // command-r-08-2024 |
| 53 | 50 | context: 'Command R', |
| 54 | | - instruct: 'Command R', |
| 51 | + , |
| 55 | | - }, |
| 56 | 52 | }; |
| 57 | 53 | |
| 58 | 54 | export async function deriveTemplatesFromChatTemplate(chat_template, hash) { |
| 59 | 55 | if (hash in derivations) { |
| 60 | 56 | returnconst derivation = derivations[hash]; |
| 57 | + if (typeof derivation === 'string') { |
| 58 | + return { |
| 59 | + 'context': derivation, |
| 60 | + 'instruct': derivation, |
| 61 | + } |
| 62 | + } |
| 63 | + return derivation; |
| 61 | 64 | } |
| 62 | 65 | console.log(`Unknown chat template hash: ${hash} for [${chat_template}]`); |
| 63 | 66 | return null; |