This repository was archived by the owner on Sep 10, 2025. It is now read-only.
Commit 90749d2
Add Granite code support (#1336)
* feat(models): Add models.json blocks for Granite Code 3b and 8b
Branch: GraniteCodeSupport
Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
* feat: Initial model params for granite code 3b
Branch: GraniteCodeSupport
Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
* fix(model config): Fix model configs for Granite Code
* Use the right tokenizer_file name
* Use the right transformer_params_key based on the file name in
model_params
* Use the updated name to indicate HF tokenizers
Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
* feat(granite): Add model params for granite-code-8b
Something isn't quite working with this model yet, but the config should be
accurate at this point.
Branch: GraniteCodeSupport
Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
* fix(deps): Add tokenizers to the deps explicitly
It was implicitly being pulled in via lm_eval -> transformers, but it's
better to have it explicit since we use it directly
Branch: GraniteCodeSupport
Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
* feat(tokenizer): Add basic support for jinja2 template rendering for HF tokenizers
This is a much simplified version of the corresponding logic in
transformers. I opted for this so that the full transformers dependency is
not added here.
CITE: https://github.com/huggingface/transformers/blob/main/src/transformers/tokenization_utils_base.py#L1522
Branch: GraniteCodeSupport
Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
* fix(chat): Add HFTokenizerChatFormatter and use it for HF tokenizers
This will allow the jinja2 templates for HF tokenizers to be applied
without needing to hard-code the formatter logic. This will likely need to
be duplicated in the embedded code version of chat.
Branch: GraniteCodeSupport
Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
* fix(deps): Add jinja2 as an explicit dep
It was getting pulled in implicitly via flask and lm_eval -> transformers,
but better to have it explicit.
Branch: GraniteCodeSupport
Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
* feat(log): Add env-based LOG_LEVEL config to CLI
Branch: GraniteCodeSupport
Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
* feat(log): Add better logging in model and generate
In generate, there were a number of commented-out log lines. These are safe
to leave in as long as lazy string interpolation is used.
Branch: GraniteCodeSupport
Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
* feat(generate): Make prepending BOS model-conigurable
And disable it for Granite Code models
Branch: GraniteCodeSupport
Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
* fix(chat): Refactor chat template logic to encapsulate all formatting in classes
The formatted strings may not be perfectly 1:1 with the previous impl, but
they should be in line with the official model guidelines:
* https://llama.meta.com/docs/model-cards-and-prompt-formats/meta-llama-3
* https://llama.meta.com/docs/model-cards-and-prompt-formats/meta-llama-2
Branch: GraniteCodeSupport
Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
* fix(chat): Fix small formatting bugs in llama3 chat formatter
Branch: GraniteCodeSupport
Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
* test: Add initial unit tests for chat formatters
There's no formal execution framework for pytest yet, but these were
helpful in ensuring that the formatting was working correctly!
To run them, install pytest and run `pytest tests/`
Branch: GraniteCodeSupport
Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
* fix(logging): Disable logging in generate unless set in the env
There is an incompatibility with logging and torch._dynamo, so this
disables it unless the developer asks for it explicitly.
NOTE: The TC team has stated that they have holistic logging on the roadmap
so this is a short-term solution pending a more robust approach.
REF: https://github.com/pytorch/torchchat/actions/runs/11963066986/job/33493237302#step:14:3599
Branch: GraniteCodeSupport
Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
* fix: Remove trailing n from llama3 <|eot_id|>
There's inconsistency in the documentation on whether or not there should
be a n after <|eot_id|>, but this maintains consistency with previous
formatting
Branch: GraniteCodeSupport
Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
---------
Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
Co-authored-by: Jack-Khuu <jack.khuu.7@gmail.com>1 parent fd1857a commit 90749d2
File tree
10 files changed
+469
-75
lines changed- install
- tests
- tokenizer
- torchchat
- cli
- model_config
- model_params
10 files changed
+469
-75
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
40 | 44 | | |
41 | 45 | | |
42 | 46 | | |
| |||
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
| 55 | + | |
| 56 | + | |
51 | 57 | | |
52 | 58 | | |
53 | 59 | | |
| |||
70 | 76 | | |
71 | 77 | | |
72 | 78 | | |
| 79 | + | |
| 80 | + | |
73 | 81 | | |
74 | 82 | | |
75 | 83 | | |
| |||
90 | 98 | | |
91 | 99 | | |
92 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
21 | 29 | | |
22 | 30 | | |
23 | 31 | | |
| |||
0 commit comments