"mmdet3d/models/task_modules/coders/smoke_bbox_coder.py" did not exist on "c10e9be2ee9246121d00828d666423ecefb725f5"
ipex.py 1.69 KB
Newer Older
1
2
import intel_extension_for_pytorch as ipex
import torch
Wang, Yi's avatar
Wang, Yi committed
3
from text_generation_server.models.flash_causal_lm import BLOCK_SIZE
4
from text_generation_server.layers.attention import Seqlen
drbh's avatar
drbh committed
5
from typing import Optional
6
7
8
9
10
11
12
13
14
15
16
17

SUPPORTS_WINDOWING = False


def attention(
    q,
    k,
    v,
    cu_seqlens,
    max_s,
    softmax_scale,
    window_size_left=-1,
18
    causal=True,
drbh's avatar
drbh committed
19
    softcap: Optional[float] = None,
20
):
21
22
    out = torch.empty_like(q)

23
    # We do not need to check window_size_left (not supported) here, so it is already checked ahead of time at model load.
drbh's avatar
drbh committed
24
    ipex.llm.functional.varlen_attention(
25
26
27
28
29
30
31
32
33
34
35
        q,
        k,
        v,
        out,
        cu_seqlens,
        cu_seqlens,
        max_s,
        max_s,
        0.0,
        softmax_scale,
        False,
36
        causal,
37
38
39
40
        False,
        None,
    )

drbh's avatar
drbh committed
41
42
    return out

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

def reshape_and_cache(
    key: torch.Tensor,
    value: torch.Tensor,
    key_cache: torch.Tensor,
    value_cache: torch.Tensor,
    slots: torch.Tensor,
):
    ipex.llm.modules.PagedAttention.reshape_and_cache(
        key, value, key_cache, value_cache, slots
    )


def paged_attention(
    query: torch.Tensor,
    key_cache: torch.Tensor,
    value_cache: torch.Tensor,
    kv_head_mapping: torch.Tensor,
    softmax_scale: float,
    block_tables: torch.Tensor,
63
    seqlen: Seqlen,
64
    max_s: int,
drbh's avatar
drbh committed
65
    softcap: Optional[float] = None,
66
):
67
    out = torch.empty_like(query)
68
    ipex.llm.modules.PagedAttention.single_query_cached_kv_attention(
69
70
71
72
73
74
75
        out,
        query,
        key_cache,
        value_cache,
        kv_head_mapping,
        softmax_scale,
        block_tables,
76
        seqlen.input_lengths,
Wang, Yi's avatar
Wang, Yi committed
77
        BLOCK_SIZE,
78
79
80
        max_s,
        None,
    )
81
    return out