"examples/avsr/doc/lip_white.png" did not exist on "d49e6e454eca30912b06f0af7e2d5357afe430ec"
LlamaDenseWeight.h 2.11 KB
Newer Older
Li Zhang's avatar
Li Zhang committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*
 * Copyright (c) OpenMMLab. All rights reserved.
 * Copyright (c) 2019-2023, NVIDIA CORPORATION.  All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

lvhan028's avatar
lvhan028 committed
18
// Modified from https://github.com/NVIDIA/FasterTransformer/blob/main/src/turbomind/layers/DenseWeight.h
Li Zhang's avatar
Li Zhang committed
19
20
21

#pragma once

lvhan028's avatar
lvhan028 committed
22
23
24
#include "src/turbomind/layers/FfnWeight.h"
#include "src/turbomind/layers/attention_layers/AttentionWeight.h"
#include "src/turbomind/utils/cuda_utils.h"
Li Zhang's avatar
Li Zhang committed
25

lvhan028's avatar
lvhan028 committed
26
namespace turbomind {
Li Zhang's avatar
Li Zhang committed
27

AllentDan's avatar
AllentDan committed
28
29
enum class WeightType : int
{
Li Zhang's avatar
Li Zhang committed
30
31
32
    kFP32,
    kFP16,
    kFP8,  // not supported yet
q.yao's avatar
q.yao committed
33
    kBF16,
Li Zhang's avatar
Li Zhang committed
34
35
36
37
38
39
40
41
42
43
44
45
46
    kINT8,
    kINT4
};

inline size_t getBitSize(WeightType type)
{
    switch (type) {
        case WeightType::kFP32:
            return 32;
        case WeightType::kFP16:
            return 16;
        case WeightType::kFP8:
            return 8;
q.yao's avatar
q.yao committed
47
48
        case WeightType::kBF16:
            return 16;
Li Zhang's avatar
Li Zhang committed
49
50
51
52
53
        case WeightType::kINT8:
            return 8;
        case WeightType::kINT4:
            return 4;
    }
54
    return 0;
Li Zhang's avatar
Li Zhang committed
55
56
57
58
59
60
61
62
63
}

template<typename T>
struct LlamaDenseWeight {
    size_t     input_dims;
    size_t     output_dims;
    void*      kernel;
    WeightType type;
    T*         bias;
64
65
    T*         scales_and_zeros;
    int        group_size;
gaoqiong's avatar
gaoqiong committed
66
    int        w4_weight_layout;
Li Zhang's avatar
Li Zhang committed
67
68
69
70
71
72
};

template<typename T>
struct LlamaAttentionWeight {
    LlamaDenseWeight<T> qkv;
    LlamaDenseWeight<T> output;
AllentDan's avatar
AllentDan committed
73
    std::vector<float>  past_kv_scale;
Li Zhang's avatar
Li Zhang committed
74
75
76
77
78
79
80
};

template<typename T>
struct LlamaFfnWeight {
    LlamaDenseWeight<T> gating;
    LlamaDenseWeight<T> intermediate;
    LlamaDenseWeight<T> output;
81
    LlamaDenseWeight<T> fused_gating_intermediate;
Li Zhang's avatar
Li Zhang committed
82
83
};

lvhan028's avatar
lvhan028 committed
84
}  // namespace turbomind