Models
ModelConfig
dataclass
Configuration class for storing model specific parameters.
Attributes:
Name | Type | Description |
---|---|---|
residual_stream_input_hook_name |
str
|
Name of the residual stream torch module where attach the hook |
residual_stream_hook_name |
str
|
Name of the residual stram torch module where attach the hook |
intermediate_stream_hook_name |
str
|
Name of the intermediate stream torch module where attach the hook |
residual_stream_input_post_layernorm_hook_name |
str
|
Name of the residual stream input post layer norm |
attn_value_hook_name |
str
|
Name of the attention value torch module where attach the hook |
attn_in_hook_name |
str
|
Name of the attention input torch module where attach the hook |
attn_out_hook_name |
str
|
Name of the attention output torch module where attach the hook |
attn_matrix_hook_name |
str
|
Name of the attention matrix torch module where attach the hook |
attn_out_proj_weight |
str
|
Name of the attention output projection weight |
attn_out_proj_bias |
str
|
Name of the attention output projection bias |
embed_tokens |
str
|
Name of the embedding tokens torch module where attach the hook |
num_hidden_layers |
int
|
Number of hidden layers |
num_attention_heads |
int
|
Number of attention heads |
hidden_size |
int
|
Hidden size of the transformer model |
num_key_value_heads |
int
|
Number of key value heads |
num_key_value_groups |
int
|
Number of key value groups |
head_dim |
int
|
Dimension of the attention head |
Source code in easyroutine/interpretability/models.py
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 |
|
ModelFactory
This class is a factory to load the model and the processor. It supports the following models:
Supported Models
The following models are supported by this factory:
- Chameleon-7b: A 7-billion parameter model for general-purpose tasks.
- Chameleon-30b: A larger version of the Chameleon series with 30 billion parameters.
- llava-hf/llava-v1.6-mistral-7b-hf: A 7-billion parameter model for multimodal tasks.
- Pixtral-12b: Optimized for image-to-text tasks.
- Emu3-Chat: Fine-tuned for conversational AI.
- Emu3-Gen: Specialized in text generation tasks.
- Emu3-Stage1: Pretrained for multi-stage training pipelines.
- hf-internal-testing: A tiny model for internal testing purposes.
Adding a New Model
To add a new model:
1. Implement its logic in the load_model
method.
2. Ensure it is correctly initialized and validated.
Source code in easyroutine/interpretability/models.py
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 |
|
load_model(model_name, attn_implementation, torch_dtype, device_map)
staticmethod
Load the model and its configuration based on the model name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_name
|
str
|
Name of the model to load. |
required |
attn_implementation
|
str
|
Attention implementation type. (eager, flash-attn, sdp) |
required |
torch_dtype
|
dtype
|
Data type of the model. |
required |
device_map
|
str
|
Device map for the model. |
required |
Returns:
Name | Type | Description |
---|---|---|
model |
HuggingFaceModel
|
Model instance. |
model_config |
ModelConfig
|
Model configuration. |
Source code in easyroutine/interpretability/models.py
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 |
|
TokenizerFactory
This class return the right tokenizer for the model. If the model is multimodal return is_a_process == True
Source code in easyroutine/interpretability/models.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
|
load_tokenizer(model_name, torch_dtype, device_map)
staticmethod
Load the tokenizer based on the model name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_name
|
str
|
Name of the model to load. |
required |
torch_dtype
|
dtype
|
Data type of the model. |
required |
device_map
|
str
|
Device map for the model. |
required |
Returns:
Name | Type | Description |
---|---|---|
processor |
Tokenizer
|
Processor instance. |
is_a_processor |
bool
|
True if the model is multimodal, False otherwise. |
Source code in easyroutine/interpretability/models.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
|