Skip to content

Commit 87d34f5

Browse files
committed
compatibility code for gpt2 in 20a and 20b - use should not need to checkout other git commits when using these versions
1 parent 32cad3b commit 87d34f5

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

+gpt2/+internal/getSupportFilePath.m

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
arguments
88
fileName (1,1) string
99
end
10+
if ismember(version('-release'),["2020a","2020b"])
11+
filePath = legacySupportFilePath(fileName);
12+
return
13+
end
1014
sd = matlab.internal.examples.utils.getSupportFileDir();
1115
localFileDir = {"data","networks"};%#ok
1216
localFile = fullfile(sd,"nnet",localFileDir{:},fileName);
@@ -15,4 +19,37 @@
1519
end
1620
fileURL = strjoin([localFileDir,fileName],"/");
1721
filePath = matlab.internal.examples.downloadSupportFile("nnet",fileURL);
22+
end
23+
24+
function filePath = legacySupportFilePath(fileName)
25+
% For releases before matlab.internal.examples.downloadSupportFile,
26+
% use manual download code. We save to the repo's root directory instead of
27+
% the userpath.
28+
% Create directories for the model.
29+
modelType = 'gpt2-355M';
30+
modelDirectory = fullfile(fileparts(mfilename('fullpath')),'..','..',modelType);
31+
filePath = fullfile(modelDirectory,fileName);
32+
iCreateDirectoryIfItDoesNotExist(modelDirectory);
33+
34+
iDownloadFileIfItDoesNotExist( ...
35+
filePath, ...
36+
"https://ssd.mathworks.com/supportfiles/nnet/data/networks/"+fileName );
37+
end
38+
39+
function iCreateDirectoryIfItDoesNotExist(directory)
40+
if ~exist(directory, 'dir')
41+
fprintf('Creating directory ''%s''...\n', directory);
42+
mkdir(directory);
43+
else
44+
fprintf('Skipped creating directory ''%s'' as it already exists\n', directory);
45+
end
46+
end
47+
48+
function iDownloadFileIfItDoesNotExist(destination, source)
49+
if ~exist(destination, 'file')
50+
fprintf('Downloading file ''%s'' ...\n', destination);
51+
websave(destination, source);
52+
else
53+
fprintf('Skipped downloading file ''%s'' as it already exists\n', destination);
54+
end
1855
end

0 commit comments

Comments
 (0)