-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_gpt.m
More file actions
49 lines (37 loc) · 1.16 KB
/
run_gpt.m
File metadata and controls
49 lines (37 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
clear
clc
%% Load weight files
modelName = "gpt2-base";
[~, files] = system("ls " + modelName + " | grep mat | sed 's/.mat//'");
% show all files | files with mat | delete .mat suffix
% split into an array of file names
files = regexp(files,"\n","split");
% combine characters into string, delete the last one, which is usless
files = convertCharsToStrings(files(1:end-1));
for i = 1:length(files)
load(modelName + "/" + files(i) + ".mat");
end
% define global variables
[NUM_LAYERS, d_model, dk, n_head] = Get_model_parameters(modelName);
clear files
%% Run GPT
Question = "What is your job?";
% define generation steps
Steps = 15;
% input Tokens start with empty array
inputTokens = [];
% initial input is loaded into the 'out' array for identical loop structure
out = bpe_encoding(Question);
% Generation steps
for i = 1:Steps
% Concat last input with last output
inputTokens = [inputTokens out];
% call generate script, it is not a function to avoid passing too many
% arguments
generate;
% load final output into 'out'
out = Script_output;
end
% Print output
final_out = [inputTokens out];
bpe_decoding(final_out)