Transformer#
salt.models.transformer_v2.Attention
#
Bases: torch.nn.Module
Multihead attention module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embed_dim |
int
|
Dimension of the input. |
required |
num_heads |
int
|
Number of attention heads. |
1
|
attn_type |
str
|
Name of backend kernel to use. |
'torch-meff'
|
dropout |
float
|
Dropout rate. |
0.0
|
bias |
bool
|
Whether to include bias terms. |
True
|
diff_attention |
bool
|
Use differential attention or not |
False
|
depth |
int
|
Number of current attention layer |
1
|
Source code in salt/models/transformer_v2.py
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 |
|
forward
#
Attention forward pass, dispatches to the appropriate backend.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
torch.Tensor
|
The pointcloud of shape (batch, x_len, dim). |
required |
kv |
torch.Tensor
|
Optional second pointcloud for cross-attn with shape (batch, kv_len, dim). |
None
|
mask |
torch.BoolTensor
|
Mask for the pointcloud x, by default None. |
None
|
kv_mask |
torch.BoolTensor
|
Mask the kv pointcloud, by default None. |
None
|
attn_mask |
torch.BoolTensor
|
Full attention mask, by default None. |
None
|
culens |
torch.Tensor
|
Cumulative lengths of the sequences in x, by default None. Only used for the flash-varlen backend. |
None
|
maxlen |
int
|
Maximum length of a sequence in the x, by default None. Only used for the flash-varlen backend. |
None
|
Returns:
Type | Description |
---|---|
torch.Tensor
|
Output of shape (batch, x_len, dim). |
Source code in salt/models/transformer_v2.py
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 |
|
salt.models.transformer_v2.GLU
#
Bases: torch.nn.Module
Dense update with gated linear unit.
See 2002.05202.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embed_dim |
int
|
Dimension of the input and output. |
required |
hidden_dim |
int | None
|
Dimension of the hidden layer. If None, defaults to embed_dim * 2. |
None
|
activation |
str
|
Activation function. |
'SiLU'
|
dropout |
float
|
Dropout rate. |
0.0
|
bias |
bool
|
Whether to include bias in the linear layers. |
True
|
gated |
bool
|
Whether to gate the output of the hidden layer. |
False
|
Source code in salt/models/transformer_v2.py
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
|
salt.models.transformer_v2.EncoderLayer
#
Bases: torch.nn.Module
Encoder layer consisting of a self-attention and a feed-forward layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embed_dim |
int
|
Dimension of the embeddings at each layer. |
required |
norm |
str
|
Normalization style, by default "LayerNorm". |
'LayerNorm'
|
drop_path |
float
|
Drop path rate, by default 0.0. |
0.0
|
ls_init |
float | None
|
Initial value for the layerscale, by default 1e-3. |
None
|
depth |
int
|
The depth of the layer, by default 1. |
1
|
dense_kwargs |
dict | None
|
Keyword arguments for salt.models.transformer_v2.GLU. |
None
|
attn_kwargs |
dict | None
|
Keyword arguments for salt.models.transformer_v2.Attention. |
None
|
Source code in salt/models/transformer_v2.py
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 |
|
salt.models.transformer_v2.TransformerV2
#
Bases: torch.nn.Module
Transformer model consisting of a stack of Transformer encoder layers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_layers |
int
|
Number of layers. |
required |
embed_dim |
int
|
Dimension of the embeddings at each layer. |
required |
out_dim |
int | None
|
Optionally project the output to a different dimension. |
None
|
norm |
str
|
Normalization style, by default "LayerNorm". |
'LayerNorm'
|
attn_type |
str
|
The backend for the attention mechanism, by default "torch-flash". Provided here because the varlen backend requires pre/post processing. |
'torch-math'
|
do_final_norm |
bool
|
Whether to apply a final normalization layer, by default True. |
True
|
num_registers |
int
|
The number of registers to add to the END of the input sequence. Registers are randomly initialised tokens of the same dimension as any other inputs after initialiser networks. See 2309.16588. |
1
|
drop_registers |
bool
|
If to drop the registers from the outputs |
False
|
kwargs |
dict
|
Keyword arguments for [salt.models.transformer_v2.EncoderLayer]. |
{}
|
Source code in salt/models/transformer_v2.py
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 |
|
Created: January 25, 2024