Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
GPT2_migraphx
Commits
b2735663
Commit
b2735663
authored
Jun 14, 2023
by
liucong8560
Browse files
Merge branch 'develop' into 'master'
Develop See merge request
!2
parents
5a36110c
f6ecdce1
Changes
28
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
66 additions
and
26 deletions
+66
-26
Src/Utility/SimpleLog.h
Src/Utility/SimpleLog.h
+1
-1
Src/Utility/tokenization.cpp
Src/Utility/tokenization.cpp
+0
-0
Src/Utility/tokenization.h
Src/Utility/tokenization.h
+0
-0
Src/Utility/utf8proc.c
Src/Utility/utf8proc.c
+0
-0
Src/Utility/utf8proc.h
Src/Utility/utf8proc.h
+0
-0
Src/Utility/utf8proc_data.c
Src/Utility/utf8proc_data.c
+0
-0
Src/main.cpp
Src/main.cpp
+65
-23
requirements.txt
requirements.txt
+0
-2
No files found.
Src/Utility/SimpleLog.h
View file @
b2735663
...
...
@@ -19,7 +19,7 @@ using namespace std;
/** 简易日志
*
*
轻量级日志系统,
不依赖于其他第三方库,只需要包含一个头文件就可以使用。提供了4种日志级别,包括INFO,DEBUG,WARN和ERROR。
* 不依赖于其他第三方库,只需要包含一个头文件就可以使用。提供了4种日志级别,包括INFO,DEBUG,WARN和ERROR。
*
* 示例1:
// 初始化日志,在./Log/目录下创建两个日志文件log1.log和log2.log(注意:目录./Log/需要存在,否则日志创建失败)
...
...
Src/
NLP/GPT2
/tokenization.cpp
→
Src/
Utility
/tokenization.cpp
View file @
b2735663
File moved
Src/
NLP/GPT2
/tokenization.h
→
Src/
Utility
/tokenization.h
View file @
b2735663
File moved
Src/
NLP/GPT2
/utf8proc.c
→
Src/
Utility
/utf8proc.c
View file @
b2735663
File moved
Src/
NLP/GPT2
/utf8proc.h
→
Src/
Utility
/utf8proc.h
View file @
b2735663
File moved
Src/
NLP/GPT2
/utf8proc_data.c
→
Src/
Utility
/utf8proc_data.c
View file @
b2735663
File moved
Src/main.cpp
View file @
b2735663
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Sample.h>
#include <GPT2.h>
#include <fstream>
#include <SimpleLog.h>
#include <Filesystem.h>
#include <tokenization.h>
void
MIGraphXSamplesUsage
(
char
*
programName
)
int
main
(
)
{
printf
(
"Usage : %s <index>
\n
"
,
programName
);
printf
(
"index:
\n
"
);
printf
(
"
\t
0) GPT2 sample.
\n
"
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
<
2
||
argc
>
2
)
// 加载GPT2模型
migraphxSamples
::
GPT2
gpt2
;
migraphxSamples
::
ErrorCode
errorCode
=
gpt2
.
Initialize
();
if
(
errorCode
!=
migraphxSamples
::
SUCCESS
)
{
MIGraphXSamplesUsage
(
argv
[
0
]
);
return
-
1
;
LOG_ERROR
(
stdout
,
"fail to initialize GPT2!
\n
"
);
exit
(
-
1
)
;
}
if
(
!
strncmp
(
argv
[
1
],
"-h"
,
2
))
LOG_INFO
(
stdout
,
"succeed to initialize GPT2
\n
"
);
// 加载词汇表,用于编码和解码
cuBERT
::
FullTokenizer
tokenizer
=
cuBERT
::
FullTokenizer
(
"../Resource/vocab_shici.txt"
);
std
::
ifstream
infile
;
std
::
string
buf
;
std
::
vector
<
std
::
string
>
output
;
infile
.
open
(
"../Resource/vocab_shici.txt"
);
while
(
std
::
getline
(
infile
,
buf
))
{
MIGraphXSamplesUsage
(
argv
[
0
]);
return
0
;
output
.
push_back
(
buf
);
}
switch
(
*
argv
[
1
])
std
::
vector
<
long
unsigned
int
>
input_id
;
char
question
[
100
];
std
::
vector
<
long
unsigned
int
>
score
;
std
::
vector
<
std
::
string
>
result
;
std
::
cout
<<
"开始和GPT2对诗,输入CTRL + Z以退出"
<<
std
::
endl
;
while
(
true
)
{
case
'0'
:
{
Sample_GPT2
();
break
;
}
default
:
// 数据预处理
std
::
cout
<<
"question: "
;
cin
.
getline
(
question
,
100
);
gpt2
.
Preprocessing
(
tokenizer
,
question
,
input_id
);
// 推理
for
(
int
i
=
0
;
i
<
50
;
++
i
)
{
long
unsigned
int
outputs
=
gpt2
.
Inference
(
input_id
);
if
(
outputs
==
102
)
{
MIGraphXSamplesUsage
(
argv
[
0
]);
break
;
}
input_id
.
push_back
(
outputs
);
score
.
push_back
(
outputs
);
}
// 将数值映射为字符
for
(
int
i
=
0
;
i
<
score
.
size
();
++
i
)
{
result
.
push_back
(
output
[
score
[
i
]]);
}
// 打印结果
std
::
cout
<<
"chatbot: "
;
std
::
cout
<<
question
;
for
(
int
j
=
0
;
j
<
result
.
size
();
++
j
)
{
std
::
cout
<<
result
[
j
];
}
std
::
cout
<<
std
::
endl
;
// 清除数据
input_id
.
clear
();
result
.
clear
();
score
.
clear
();
}
return
0
;
}
\ No newline at end of file
requirements.txt
deleted
100644 → 0
View file @
5a36110c
./3rdParty/opencv-3.4.11_mini.tar.gz
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment