modules.easydel_modelling_utils
EasyDeLFlaxPretrainedModel
Bases: FlaxPreTrainedModel
Source code in src/python/easydel/modules/easydel_modelling_utils.py
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 |
|
__repr__()
The repr function is used to generate a string representation of an object. This function should return a string that can be parsed by the Python interpreter to recreate the object. The repr function is called when you use print() on an object, or when you type its name in the REPL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Refer to the instance of the class |
required |
Returns:
Type | Description |
---|---|
A string representation of the object |
Source code in src/python/easydel/modules/easydel_modelling_utils.py
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 |
|
__str__()
The str function is called when you use the print function or when str() is used. It should return a string representation of the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Refer to the instance of the class |
required |
Returns:
Type | Description |
---|---|
The object's string representation |
Source code in src/python/easydel/modules/easydel_modelling_utils.py
614 615 616 617 618 619 620 621 622 623 |
|
get_decoder()
The get_decoder function is used to create a decoder object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Represent the instance of the class |
required |
Returns:
Type | Description |
---|---|
A decoder object |
Source code in src/python/easydel/modules/easydel_modelling_utils.py
527 528 529 530 531 532 533 534 |
|
get_input_embeddings()
The get_input_embeddings function returns the embedding layer of the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Refer to the current object |
required |
Returns:
Type | Description |
---|---|
The embedding layer of the model |
Source code in src/python/easydel/modules/easydel_modelling_utils.py
476 477 478 479 480 481 482 483 |
|
get_output_embeddings()
The get_output_embeddings function returns the output embeddings of a model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Represent the instance of the class |
required |
Returns:
Type | Description |
---|---|
The output embeddings of the model |
Source code in src/python/easydel/modules/easydel_modelling_utils.py
494 495 496 497 498 499 500 501 |
|
prepare_inputs_for_generation(input_ids, max_length, attention_mask=None)
The prepare_inputs_for_generation function is used to prepare the inputs for a generation task.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Access variables that belong to the class |
required | |
input_ids |
Pass in the input tokens |
required | |
max_length |
Set the length of the sequence to be generated |
required | |
attention_mask |
Optional[Array]
|
Optional[chex.Array]: Mask the attention weights |
None
|
Returns:
Type | Description |
---|---|
A dictionary of the past_key_values, attention_mask and position ids |
Source code in src/python/easydel/modules/easydel_modelling_utils.py
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 |
|
set_decoder(decoder)
The set_decoder function is used to set the decoder for a given encoder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Refer to the object itself |
required | |
decoder |
Set the decoder for a given encoder |
required |
Returns:
Type | Description |
---|---|
A decoder |
Source code in src/python/easydel/modules/easydel_modelling_utils.py
517 518 519 520 521 522 523 524 525 |
|
set_input_embeddings(value)
The set_input_embeddings function is used to set the embedding module of the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Represent the instance of the class |
required | |
value |
Set the embeddings of the model |
required |
Source code in src/python/easydel/modules/easydel_modelling_utils.py
485 486 487 488 489 490 491 492 |
|
set_output_embeddings(new_embeddings)
The set_output_embeddings function is used to set the output embeddings of a model. This function can be used to change the output embedding layer of a pretrained model in order to finetune it to some downstream task. Changing this layer has an effect only if the model has already been fine-tuned on some task (e.g., for classification). If you are training your own language models, you should call this function before you start training.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Represent the instance of the class |
required | |
new_embeddings |
Set the embeddings of the output layer |
required |
Returns:
Type | Description |
---|---|
A new embedding layer |
Source code in src/python/easydel/modules/easydel_modelling_utils.py
503 504 505 506 507 508 509 510 511 512 513 514 515 |
|
EasyDeLPretrainedConfig
Bases: PretrainedConfig
It initializes all the attributes of an object, and it's called when you create a new instance of that class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Refer to the instance of the class |
required | |
axis_dims |
Sequence[int]
|
Sequence[int]: Specify the number of dimensions for each axis |
(1, -1, 1, 1)
|
axis_names |
Sequence[str]
|
Sequence[str]: Set the names of the axes |
('dp', 'fsdp', 'tp', 'sp')
|
attn_mechanism |
AVAILABLE_ATTENTION_MECHANISMS
|
Literal["vanilla", "flash", "splash", "ring"]: attention mechanism to use |
'sharded_vanilla'
|
block_k |
int
|
int: block size of key_states |
128
|
block_q |
int
|
int: block size of query_states |
128
|
block_b |
int
|
int: block size of bias |
1
|
block_q_major_dkv |
int | None
|
int: block size of block_q_major_dkv |
None
|
block_k_major_dkv |
int | None
|
int: block size of block_k_major_dkv |
None
|
block_k_dkv |
int | None
|
int: block size of block_k_dkv |
None
|
block_q_dkv |
int | None
|
int: block size of block_q_dkv |
None
|
block_k_major_dq |
int | None
|
int: block size of block_k_major_dq |
None
|
block_k_dq |
int | None
|
int: block size of block_k_dq |
None
|
block_q_dq |
int | None
|
int: block size of block_q_dq |
None
|
query_partition_spec |
PartitionSpec
|
PartitionSpec: Specify the partitioning of the query tensor |
PartitionSpec(('dp', 'fsdp'), 'sp', 'tp', None)
|
key_partition_spec |
PartitionSpec
|
PartitionSpec: Partition the key matrix |
PartitionSpec(('dp', 'fsdp'), 'sp', 'tp', None)
|
value_partition_spec |
PartitionSpec
|
PartitionSpec: Specify the partitioning of the value tensor |
PartitionSpec(('dp', 'fsdp'), 'sp', 'tp', None)
|
bias_partition_spec |
PartitionSpec
|
PartitionSpec: Specify the Attention Bias partition spec |
PartitionSpec(('dp', 'fsdp'), None, None, None)
|
attention_partition_spec |
PartitionSpec
|
PartitionSpec: Specify the partitioning of the attention weights |
PartitionSpec(('dp', 'fsdp'), 'sp', 'tp', None)
|
shard_attention_computation |
bool
|
bool: whenever to shard qkv b for attention |
True
|
use_sharding_constraint |
bool
|
bool: whether to use sharding constraint for the arrays |
False
|
use_scan_mlp |
bool
|
bool: Determine whether to use scan_mlp or not |
True
|
backend |
Optional[None]
|
Optional[None]: Specify the backend to use |
default_backend()
|
flash_attention_backward_pass_impl |
Literal['triton', 'xla']
|
Literal["triton", "xla"]: Specify the backward pass kernel for flash attention |
'triton'
|
Source code in src/python/easydel/modules/easydel_modelling_utils.py
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 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 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 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 |
|
__repr__()
The repr function is used to generate a string representation of an object. This function should return a string that can be parsed by the Python interpreter to recreate the object. The repr function is called when you use print() on an object, or when you type its name in the REPL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Refer to the instance of the class |
required |
Returns:
Type | Description |
---|---|
A string representation of the object |
Source code in src/python/easydel/modules/easydel_modelling_utils.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 |
|
__str__()
The str function is called when you use the print function or when str() is used. It should return a string representation of the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Refer to the instance of the class |
required |
Returns:
Type | Description |
---|---|
The object's string representation |
Source code in src/python/easydel/modules/easydel_modelling_utils.py
443 444 445 446 447 448 449 450 451 452 |
|
add_basic_configurations(axis_dims=..., axis_names=..., attn_mechanism=..., block_k=..., block_q=..., block_b=..., block_k_major=..., block_q_major_dkv=..., block_k_major_dkv=..., block_k_dkv=..., block_q_dkv=..., block_k_major_dq=..., block_k_dq=..., block_q_dq=..., query_partition_spec=..., generation_query_partition_spec=..., key_partition_spec=..., value_partition_spec=..., bias_partition_spec=..., attention_partition_spec=..., generation_bias_partition_spec=..., generation_attention_partition_spec=..., shard_attention_computation=..., use_sharded_kv_caching=..., backend=..., easy_method=..., bits=..., scan_ring_attention=..., scan_attention_layers=..., use_sharding_constraint=..., use_scan_mlp=..., scan_mlp_chunk_size=..., attention_axis_name=..., quantize_kv_cache=..., flash_attention_backward_pass_impl=...)
It initializes all the attributes of an object, and it's called when you create a new instance of that class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Refer to the instance of the class |
required | |
axis_dims |
Sequence[int]
|
Sequence[int]: Specify the number of dimensions for each axis |
...
|
axis_names |
Sequence[str]
|
Sequence[str]: Set the names of the axes |
...
|
attn_mechanism |
AVAILABLE_ATTENTION_MECHANISMS
|
Literal["vanilla", "flash", "splash"]: attention mechanism to use |
...
|
block_k |
int
|
int: block size of key_states |
...
|
block_q |
int
|
int: block size of query_states |
...
|
block_b |
int
|
int: block size of bias |
...
|
block_k_major |
int
|
int: block size if key major |
...
|
block_q_major_dkv |
int | None
|
int: block size of block_q_major_dkv |
...
|
block_k_major_dkv |
int | None
|
int: block size of block_k_major_dkv |
...
|
block_k_dkv |
int | None
|
int: block size of block_k_dkv |
...
|
block_q_dkv |
int | None
|
int: block size of block_q_dkv |
...
|
block_k_major_dq |
int | None
|
int: block size of block_k_major_dq |
...
|
block_k_dq |
int | None
|
int: block size of block_k_dq |
...
|
block_q_dq |
int | None
|
int: block size of block_q_dq |
...
|
query_partition_spec |
PartitionSpec
|
PartitionSpec: Specify the partitioning of the query tensor |
...
|
key_partition_spec |
PartitionSpec
|
PartitionSpec: Partition the key matrix |
...
|
value_partition_spec |
PartitionSpec
|
PartitionSpec: Specify the partitioning of the value tensor |
...
|
bias_partition_spec |
PartitionSpec
|
PartitionSpec: Specify the Attention Bias partition spec |
...
|
attention_partition_spec |
PartitionSpec
|
PartitionSpec: Specify the partitioning of the attention weights |
...
|
generation_attention_partition_spec |
PartitionSpec
|
: PartitionSpec: Specify the partitioning of the attention weights in generation process |
...
|
generation_bias_partition_spec |
PartitionSpec
|
: PartitionSpec: Specify the partitioning of the Attention Bias partition spec in generation process |
...
|
generation_query_partition_spec |
PartitionSpec
|
: PartitionSpec: Specify the partitioning of the query tensor in generation process |
...
|
shard_attention_computation |
bool
|
bool: whenever to use shard_map for attention |
...
|
use_sharded_kv_caching |
bool
|
bool: whenever to use shard_map and sharding for key and value |
...
|
backend |
Optional[None]
|
Optional[None]: Specify the backend to use |
...
|
easy_method |
Literal['train', 'serve', 'convert']
|
Literal["train", "serve", "convert"]: easydel Quantization Method to be applied for |
...
|
bits |
Optional[int]
|
Optional[int]: Model bits for quantization |
...
|
use_sharding_constraint |
bool
|
bool: whether to use sharding constraint for the arrays |
...
|
scan_ring_attention |
bool
|
bool: Whether to use can for ring attention |
...
|
scan_attention_layers |
bool
|
bool: Whether to use can for attention layers |
...
|
use_scan_mlp |
bool
|
bool: Determine whether to use scan_mlp or not |
...
|
scan_mlp_chunk_size |
int
|
int: Size of chunks in scan MLP. |
...
|
attention_axis_name |
str
|
str: Name of the attention axis name |
...
|
quantize_kv_cache |
bool
|
bool: Whether to quantize Key/Value in attention for generation process. |
...
|
flash_attention_backward_pass_impl |
Literal['triton', 'xla']
|
Literal["triton", "xla"]: Specify the backward pass kernel for flash attention |
...
|
Source code in src/python/easydel/modules/easydel_modelling_utils.py
255 256 257 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 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
|
create_mesh(axis_dims=(1, -1, 1, 1), axis_names=('dp', 'fsdp', 'tp', 'sp'), backend='')
staticmethod
The create_mesh function creates a mesh object that can be used to shard arrays.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis_dims |
Sequence[int]
|
Sequence[int]: Specify the dimensions of the mesh |
(1, -1, 1, 1)
|
axis_names |
Sequence[str]
|
Sequence[str]: Name the axes of the mesh |
('dp', 'fsdp', 'tp', 'sp')
|
backend |
Specify the backend to use |
''
|
Returns:
Type | Description |
---|---|
A mesh object |
Source code in src/python/easydel/modules/easydel_modelling_utils.py
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 |
|
get_axis_dims()
The get_axis_dims function returns a sequence of integers representing the dimensions of each axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Represent the instance of the class |
required |
Returns:
Type | Description |
---|---|
Sequence[int]
|
The dimensions of the axes |
Source code in src/python/easydel/modules/easydel_modelling_utils.py
224 225 226 227 228 229 230 231 232 |
|
get_axis_names()
The get_axis_names function returns a list of the names of the axes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Represent the instance of the class |
required |
Returns:
Type | Description |
---|---|
Sequence[str]
|
A list of the names of all axes |
Source code in src/python/easydel/modules/easydel_modelling_utils.py
234 235 236 237 238 239 240 241 242 |
|
get_backend()
The get_backend function returns the backend that is currently being used. If no backend has been set, it will return the default JAX backend.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Bind the method to an object |
required |
Returns:
Type | Description |
---|---|
str
|
The backend platform |
Source code in src/python/easydel/modules/easydel_modelling_utils.py
244 245 246 247 248 249 250 251 252 253 |
|
get_partition_rules(fully_sharded_data_parallel=True)
The get_partition_rules function is used to specify how the parameters of a model are partitioned across devices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Access the attributes of the class |
required | |
fully_sharded_data_parallel |
bool
|
bool: Determine whether the model is fully sharded or not |
True
|
Returns:
Type | Description |
---|---|
A tuple of tuples |
Source code in src/python/easydel/modules/easydel_modelling_utils.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
|
jax_mesh()
The jax_mesh function is a helper function that creates a Mesh object from the axis_dims and axis_names attributes of an object, which are assumed to be lists of integers and strings, respectively. The backend attribute is also used if it exists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Refer to the object itself |
required |
Returns:
Type | Description |
---|---|
Mesh
|
A jaxMesh |
Source code in src/python/easydel/modules/easydel_modelling_utils.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
|