GPT2.h 905 Bytes
Newer Older
liucong's avatar
liucong committed
1
2
#ifndef __GPT2_H__
#define __GPT2_H__
3
4
5
6
7
8
9
10

#include <cstdint>
#include <string>
#include <migraphx/program.hpp>
#include <tokenization.h>

namespace migraphxSamples
{
liucong's avatar
liucong committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
typedef enum _ErrorCode
{
    SUCCESS = 0,
    MODEL_NOT_EXIST,
    CONFIG_FILE_NOT_EXIST,
    FAIL_TO_LOAD_MODEL,
    FAIL_TO_OPEN_CONFIG_FILE,
} ErrorCode;

typedef struct _Predictions
{
    long unsigned int index;
    float predictionvalue;
} Predictions;
25
26
27
28

class GPT2
{

liucong's avatar
liucong committed
29
    public:
30
    GPT2();
liucong's avatar
liucong committed
31

32
33
    ~GPT2();

liucong's avatar
liucong committed
34
    ErrorCode Initialize();
35
36

    ErrorCode Preprocessing(cuBERT::FullTokenizer tokenizer,
liucong's avatar
liucong committed
37
38
                            char* question,
                            std::vector<long unsigned int>& input_id);
39

liucong's avatar
liucong committed
40
    long unsigned int Inference(const std::vector<long unsigned int>& input_id);
41

liucong's avatar
liucong committed
42
    private:
43
44
45
46
47
    migraphx::program net;
    std::string inputName;
    migraphx::shape inputShape;
};

liucong's avatar
liucong committed
48
} // namespace migraphxSamples
49
#endif