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
|
Source code in salt/models/transformer_v2.py
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 |
|
forward
#
Attention forward pass.
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
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 |
|
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
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 |
|
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
|
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
453 454 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 |
|
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
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 |
|
Created: January 25, 2024