unitorch.cli.models.llama¤
LlamaProcessor¤
Tip
core/process/llama
is the section for configuration of LlamaProcessor.
Bases: LlamaProcessor
Processor for Llama models.
Initialize the LlamaProcessor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vocab_path |
str
|
The path to the vocabulary file. |
required |
max_seq_length |
int
|
The maximum sequence length. Defaults to 128. |
128
|
max_gen_seq_length |
int
|
The maximum generated sequence length. Defaults to 128. |
128
|
Source code in src/unitorch/cli/models/llama/processing.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
from_core_configure
classmethod
¤
from_core_configure(config, **kwargs)
Create an instance of LlamaProcessor from a core configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
The core configuration. |
required | |
**kwargs |
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
LlamaProcessor |
An instance of LlamaProcessor. |
Source code in src/unitorch/cli/models/llama/processing.py
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 |
|
LlamaForClassification¤
Tip
core/model/classification/llama
is the section for configuration of LlamaForClassification.
Bases: LlamaForClassification
Llama model for classification tasks.
Initialize the LlamaForClassification model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_path |
str
|
The path to the model configuration file. |
required |
num_classes |
int
|
The number of classes for classification. Defaults to 1. |
1
|
gradient_checkpointing |
bool
|
Whether to use gradient checkpointing during training. Defaults to False. |
False
|
Source code in src/unitorch/cli/models/llama/modeling.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
forward ¤
forward(
input_ids: Tensor,
attention_mask: Optional[Tensor] = None,
position_ids: Optional[Tensor] = None,
)
Perform a forward pass on the LlamaForClassification model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_ids |
Tensor
|
The input tensor containing the input IDs. |
required |
attention_mask |
Tensor
|
The attention mask tensor. Defaults to None. |
None
|
position_ids |
Tensor
|
The position IDs tensor. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
ClassificationOutputs |
The output of the classification model. |
Source code in src/unitorch/cli/models/llama/modeling.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
from_core_configure
classmethod
¤
from_core_configure(config, **kwargs)
Create an instance of LlamaForClassification from a core configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
The core configuration. |
required | |
**kwargs |
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
LlamaForClassification |
An instance of LlamaForClassification. |
Source code in src/unitorch/cli/models/llama/modeling.py
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 |
|
LlamaForGeneration¤
Tip
core/model/generation/llama
is the section for configuration of LlamaForGeneration.
Bases: LlamaForGeneration
Llama model for generation tasks.
Initialize the LlamaForGeneration model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_path |
str
|
The path to the model configuration file. |
required |
gradient_checkpointing |
bool
|
Whether to use gradient checkpointing during training. Defaults to False. |
False
|
Source code in src/unitorch/cli/models/llama/modeling.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
forward ¤
forward(
input_ids: Tensor,
attention_mask: Optional[Tensor] = None,
position_ids: Optional[Tensor] = None,
)
Perform a forward pass on the LlamaForGeneration model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_ids |
Tensor
|
The input tensor containing the input IDs. Defaults to None. |
required |
attention_mask |
Tensor
|
The attention mask tensor. Defaults to None. |
None
|
position_ids |
Tensor
|
The position IDs tensor. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
GenerationOutputs |
The output of the generation model. |
Source code in src/unitorch/cli/models/llama/modeling.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
|
from_core_configure
classmethod
¤
from_core_configure(config, **kwargs)
Create an instance of LlamaForGeneration from a core configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
The core configuration. |
required | |
**kwargs |
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
LlamaForGeneration |
An instance of LlamaForGeneration. |
Source code in src/unitorch/cli/models/llama/modeling.py
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 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
generate ¤
generate(
input_ids: Tensor,
num_beams: Optional[int] = 5,
decoder_start_token_id: Optional[int] = 1,
decoder_end_token_id: Optional[
Union[int, List[int]]
] = 2,
num_return_sequences: Optional[int] = 1,
min_gen_seq_length: Optional[int] = 0,
max_gen_seq_length: Optional[int] = 48,
repetition_penalty: Optional[float] = 1.0,
no_repeat_ngram_size: Optional[int] = 0,
early_stopping: Optional[bool] = True,
length_penalty: Optional[float] = 1.0,
num_beam_groups: Optional[int] = 1,
diversity_penalty: Optional[float] = 0.0,
do_sample: Optional[bool] = False,
temperature: Optional[float] = 1.0,
top_k: Optional[int] = 50,
top_p: Optional[float] = 1.0,
)
Generate sequences using the Llama model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_ids |
Tensor
|
Input token IDs. |
required |
num_beams |
int
|
Number of beams for beam search. Defaults to 5. |
5
|
decoder_start_token_id |
int
|
Decoder start token ID. Defaults to 1. |
1
|
decoder_end_token_id |
int or List[int]
|
The ID(s) of the decoder end token(s). Defaults to 2. |
2
|
num_return_sequences |
int
|
Number of generated sequences to return. Defaults to 1. |
1
|
min_gen_seq_length |
int
|
Minimum generation sequence length. Defaults to 0. |
0
|
max_gen_seq_length |
int
|
Maximum generation sequence length. Defaults to 48. |
48
|
repetition_penalty |
float
|
Repetition penalty. Defaults to 1.0. |
1.0
|
no_repeat_ngram_size |
int
|
Size of n-grams to prevent repetition. Defaults to 0. |
0
|
early_stopping |
bool
|
Whether to perform early stopping. Defaults to True. |
True
|
length_penalty |
float
|
Length penalty. Defaults to 1.0. |
1.0
|
num_beam_groups |
int
|
Number of beam groups for diverse beam search. Defaults to 1. |
1
|
diversity_penalty |
float
|
Diversity penalty for diverse beam search. Defaults to 0.0. |
0.0
|
do_sample |
bool
|
Whether to use sampling for generation. Defaults to False. |
False
|
temperature |
float
|
Sampling temperature. Defaults to 1.0. |
1.0
|
top_k |
int
|
Top-k sampling parameter. Defaults to 50. |
50
|
top_p |
float
|
Top-p sampling parameter. Defaults to 1.0. |
1.0
|
Returns:
Name | Type | Description |
---|---|---|
GenerationOutputs |
The generation outputs. |
Source code in src/unitorch/cli/models/llama/modeling.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
|