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