vllm.model_executor.models.deepencoder
¶
Classes:
-
Block–Transformer blocks with support of window attention and residual propagation
-
DeepEncoderConv2d–Implement an ungrouped, undilated SAM convolution with GEMM.
-
ImageEncoderViT– -
PatchEmbed–Image to Patch Embedding.
-
RelPosAttention–Multi-head Attention block with relative position embeddings.
Functions:
-
add_decomposed_rel_pos–Calculate decomposed Relative Positional Embeddings from MViTv2.
-
deepencoder_rel_pos_attention–Run DeepEncoder global attention with fused relative-position bias.
-
get_rel_pos–Get relative positional embeddings according to the relative positions of
-
window_partition–Partition into non-overlapping windows with padding if needed.
-
window_unpartition–Window unpartition into original sequences and removing padding.
Block
¶
Bases: Module
Transformer blocks with support of window attention and residual propagation blocks
Methods:
-
__init__–Args:
Source code in vllm/model_executor/models/deepencoder.py
__init__(dim, num_heads, mlp_ratio=4.0, qkv_bias=True, norm_layer=nn.LayerNorm, act_layer=nn.GELU, use_rel_pos=False, rel_pos_zero_init=True, window_size=0, input_size=None)
¶
Args: dim (int): Number of input channels. num_heads (int): Number of attention heads in each ViT block. mlp_ratio (float): Ratio of mlp hidden dim to embedding dim. qkv_bias (bool): If True, add a learnable bias to query, key, value. norm_layer (nn.Module): Normalization layer. act_layer (nn.Module): Activation layer. use_rel_pos (bool): If True, add relative positional embeddings to the attention map. rel_pos_zero_init (bool): If True, zero initialize relative positional parameters. window_size (int): Window size for window attention blocks. If it equals 0, then use global attention. input_size (tuple(int, int) or None): Input resolution for calculating the relative positional parameter size.
Source code in vllm/model_executor/models/deepencoder.py
DeepEncoderConv2d
¶
Bases: Conv2dLayer
Implement an ungrouped, undilated SAM convolution with GEMM.
Source code in vllm/model_executor/models/deepencoder.py
ImageEncoderViT
¶
Bases: Module
Methods:
-
__init__–Args:
Source code in vllm/model_executor/models/deepencoder.py
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 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 495 | |
__init__(img_size=1024, patch_size=16, in_chans=3, embed_dim=768, depth=12, num_heads=12, mlp_ratio=4.0, out_chans=256, qkv_bias=True, norm_layer=nn.LayerNorm, act_layer=nn.GELU, use_abs_pos=True, use_rel_pos=False, rel_pos_zero_init=True, window_size=0, global_attn_indexes=(), last_conv_output=1024)
¶
Args: img_size (int): Input image size. patch_size (int): Patch size. in_chans (int): Number of input image channels. embed_dim (int): Patch embedding dimension. depth (int): Depth of ViT. num_heads (int): Number of attention heads in each ViT block. mlp_ratio (float): Ratio of mlp hidden dim to embedding dim. qkv_bias (bool): If True, add a learnable bias to query, key, value. norm_layer (nn.Module): Normalization layer. act_layer (nn.Module): Activation layer. use_abs_pos (bool): If True, use absolute positional embeddings. use_rel_pos (bool): If True, add relative positional embeddings to the attention map. rel_pos_zero_init (bool): If True, zero initialize relative positional parameters. window_size (int): Window size for window attention blocks. global_attn_indexes (list): Indexes for blocks using global attention.
Source code in vllm/model_executor/models/deepencoder.py
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 453 454 455 456 457 458 459 460 461 462 463 464 | |
PatchEmbed
¶
Bases: Module
Image to Patch Embedding.
Methods:
-
__init__–Args:
Source code in vllm/model_executor/models/deepencoder.py
__init__(kernel_size=(16, 16), stride=(16, 16), padding=(0, 0), in_chans=3, embed_dim=768)
¶
Args: kernel_size (Tuple): kernel size of the projection layer. stride (Tuple): stride of the projection layer. padding (Tuple): padding size of the projection layer. in_chans (int): Number of input image channels. embed_dim (int): Patch embedding dimension.
Source code in vllm/model_executor/models/deepencoder.py
RelPosAttention
¶
Bases: PluggableLayer
Multi-head Attention block with relative position embeddings.
Methods:
-
__init__–Args:
Source code in vllm/model_executor/models/deepencoder.py
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 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 | |
__init__(dim, num_heads=8, qkv_bias=True, use_rel_pos=False, use_triton_attention=False, rel_pos_zero_init=True, input_size=None)
¶
Args: dim (int): Number of input channels. num_heads (int): Number of attention heads. qkv_bias (bool): If True, add a learnable bias to query, key, value. use_triton_attention (bool): If True, fuse relative position bias in a Triton attention kernel on CUDA-alike platforms. rel_pos_zero_init (bool): If True, zero initialize relative positional parameters. input_size (tuple(int, int) or None): Input resolution for calculating the relative positional parameter size.
Source code in vllm/model_executor/models/deepencoder.py
_pack_conv2d_windows_kernel(x_ptr, rows_ptr, stride_b, stride_c, stride_h, stride_w, INPUT_H, INPUT_W, OUTPUT_H, OUTPUT_W, KERNEL_H, KERNEL_W, STRIDE_H, STRIDE_W, PAD_H, PAD_W, ROW_SIZE, BLOCK_SIZE)
¶
Pack zero-padded windows into contiguous rows for a SAM convolution.
Source code in vllm/model_executor/models/deepencoder.py
add_decomposed_rel_pos(q, rel_pos_h, rel_pos_w, q_size, k_size)
¶
Calculate decomposed Relative Positional Embeddings from MViTv2. https://github.com/facebookresearch/mvit/blob/19786631e330df9f3622e5402b4a419a263a2c80/mvit/models/attention.py Args: q (Tensor): query q in the attention layer with shape (B, q_h * q_w, C). rel_pos_h (Tensor): relative position embeddings (Lh, C) for height axis. rel_pos_w (Tensor): relative position embeddings (Lw, C) for width axis. q_size (Tuple): spatial sequence size of query q with (q_h, q_w). k_size (Tuple): spatial sequence size of key k with (k_h, k_w).
Returns:
-
attn(Tensor) –attention map with added relative positional embeddings.
Source code in vllm/model_executor/models/deepencoder.py
deepencoder_rel_pos_attention(q, k, v, rel_h, rel_w, width, scale)
¶
Run DeepEncoder global attention with fused relative-position bias.
Source code in vllm/model_executor/models/deepencoder.py
get_rel_pos(q_size, k_size, rel_pos)
¶
Get relative positional embeddings according to the relative positions of query and key sizes.
Parameters:
-
(q_size¶int) –size of query q.
-
(k_size¶int) –size of key k.
-
(rel_pos¶Tensor) –relative position embeddings (L, C).
Returns:
-
Tensor–Extracted positional embeddings according to relative positions.
Source code in vllm/model_executor/models/deepencoder.py
window_partition(x, window_size)
¶
Partition into non-overlapping windows with padding if needed.
Parameters:
Returns:
-
windows(Tensor) –windows after partition with [B * num_windows, window_size, window_size, C].
-
(Hp, Wp)–padded height and width before partition
Source code in vllm/model_executor/models/deepencoder.py
window_unpartition(windows, window_size, pad_hw, hw)
¶
Window unpartition into original sequences and removing padding.
Parameters:
-
(windows¶tensor) –input tokens with [B * num_windows, window_size, window_size, C].
-
(window_size¶int) –window size.
-
(pad_hw¶Tuple) –padded height and width (Hp, Wp).
-
(hw¶Tuple) –original height and width (H, W) before padding.
Returns:
-
x(Tensor) –unpartitioned sequences with [B, H, W, C].