6
6
http-equiv ="origin-trial "
7
7
content ="Anx9P4m5tzLOL/wLICKy/mA+DRyoSsTkyqmnK5t+S7oyw7A2SeBI2jO4LKqoQiQgChP2MTtqMNKofelMwvGtPQsAAABKeyJvcmlnaW4iOiJodHRwczovL2ttZWFucy5vcmc6NDQzIiwiZmVhdHVyZSI6IldlYkdQVSIsImV4cGlyeSI6MTY5MTcxMTk5OX0= "
8
8
/>
9
+ < link rel ="stylesheet " href ="styles.css ">
9
10
< script src ="tokenizer.js "> </ script >
10
11
< script src ="instructions.js "> </ script >
11
12
< script src ="model.js "> </ script >
12
13
< script src ="visuals.js "> </ script >
13
14
< script src ="globals.js "> </ script >
14
15
</ head >
15
16
< body >
16
- < h1 > WebGPU GPT Model Demo</ h1 >
17
- < p id ="webgpuSupportMessage "> Checking WebGPU support...</ p >
18
- < p >
19
- < i > PS: Loading models is 5x slower on the web rather than running locally. Just < a href ="https://github.com/0hq/WebGPT "> clone the repo</ a > and open!</ i >
20
- </ p >
21
-
22
- < button class ="loadModelButton " onclick ="loadModel('better_shakespeare', 'char') " disabled > Load Shakespeare Model</ button >
23
- < button class ="loadModelButton " onclick ="loadModel('gpt2', 'bpe') " disabled > Load GPT2 117M Model</ button >
24
- < button id ="destroyCacheButton " onclick ="destroyCache() " disabled > Destroy Cache</ button >
25
-
26
- < p >
27
- < i > Special models (download required):</ i >
28
- </ p >
29
- < button class ="loadModelButton " onclick ="loadModel('large-models/gpt2-medium', 'bpe') " disabled > Load GPT2 377M Model</ button >
30
- < button class ="loadModelButton " onclick ="loadModel('large-models/gpt2-large', 'bpe') " disabled > Load GPT2 777M Model</ button >
31
- < button class ="loadModelButton " onclick ="loadModel('large-models/gpt2-xl', 'bpe') " disabled > Load GPT2 1.5B Model</ button >
32
-
33
- < br />
34
- < br />
35
- < label for ="tokens "> Number of tokens:</ label >
36
- < input type ="number " min ="1 " max ="300 " value ="100 " id ="tokensInput " disabled />
37
- < br /> < br />
38
- < label for ="topK "> Top K:</ label >
39
- < input type ="number " min ="1 " max ="100 " value ="2 " id ="topKInput " disabled />
40
- < br /> < br />
41
- < label for ="temperature "> Temperature:</ label >
42
- < input type ="number " step ="0.01 " min ="0.1 " max ="2 " value ="1 " id ="temperatureInput " disabled />
43
- < br /> < br />
44
- < button id ="generateButton " onclick ="startGeneration() " disabled > Generate Text</ button >
45
- < br /> < br />
46
- < textarea id ="prompt " rows ="15 " cols ="50 " disabled >
17
+ < div class ="container ">
18
+
19
+ < h1 > WebGPU GPT Model Demo</ h1 >
20
+ < h3 id ="webgpuSupportMessage " class ="support-message "> Checking WebGPU support...</ h3 >
21
+ < p >
22
+ < i > PS: Loading models is 5x slower on the web rather than running locally. Just < a href ="https://github.com/0hq/WebGPT "> clone the repo</ a > and open!</ i >
23
+ </ p >
24
+
25
+ < button class ="loadModelButton " onclick ="loadModel('better_shakespeare', 'char', this) " disabled >
26
+ < span class ="button-text "> Load Shakespeare Model</ span >
27
+ </ button >
28
+ < button class ="loadModelButton " onclick ="loadModel('gpt2', 'bpe', this) " disabled >
29
+ < span class ="button-text "> Load GPT2 117M Model</ span >
30
+ </ button >
31
+ < button id ="destroyCacheButton " onclick ="destroyCache() " disabled > Destroy Cache</ button >
32
+
33
+ < p >
34
+ < i > Special models (download required):</ i >
35
+ </ p >
36
+ < button class ="loadModelButton " onclick ="loadModel('large-models/gpt2-medium', 'bpe', this) " disabled >
37
+ < span class ="button-text "> Load GPT2 377M Model</ span >
38
+ </ button >
39
+ < button class ="loadModelButton " onclick ="loadModel('large-models/gpt2-large', 'bpe', this) " disabled >
40
+ < span class ="button-text "> Load GPT2 777M Model</ span >
41
+ </ button >
42
+ < button class ="loadModelButton " onclick ="loadModel('large-models/gpt2-xl', 'bpe', this) " disabled >
43
+ < span class ="button-text "> Load GPT2 1.5B Model</ span >
44
+ </ button >
45
+
46
+ < div >
47
+ < button id ="generateButton " onclick ="startGeneration() " disabled > Generate Text</ button >
48
+ < label for ="tokens "> Number of tokens:</ label >
49
+ < input type ="number " min ="1 " max ="300 " value ="100 " id ="tokensInput " disabled />
50
+ < label for ="topK "> Top K:</ label >
51
+ < input type ="number " min ="1 " max ="100 " value ="2 " id ="topKInput " disabled />
52
+ < label for ="temperature "> Temperature:</ label >
53
+ < input type ="number " step ="0.01 " min ="0.1 " max ="2 " value ="1 " id ="temperatureInput " disabled />
54
+ < textarea class ="prompt " id ="prompt " rows ="15 " cols ="50 " disabled >
47
55
WILL:
48
56
Ah, how dare you challenge me?
49
57
Have you forgotten I built WebGPT? </ textarea
50
58
>
59
+ </ div >
51
60
< br /> < br />
52
61
< button id ="updateVisuals " onclick ="updateVisuals() " disabled > Force Update Visuals</ button >
53
62
< br /> < br />
54
63
< div id ="visualsContainer "> </ div >
64
+ </ div >
55
65
< script >
56
66
const webgpuSupportMessage = document . getElementById ( "webgpuSupportMessage" ) ;
57
67
const loadModelButton = document . getElementsByClassName ( "loadModelButton" ) ;
@@ -74,9 +84,11 @@ <h1>WebGPU GPT Model Demo</h1>
74
84
if ( ! navigator . gpu ) {
75
85
webgpuSupportMessage . innerHTML =
76
86
"WebGPU is not supported in your browser yet. Update Chrome to v113 or download <a href='https://www.google.com/chrome/canary/'>Chrome Canary</a>. Also available on <a href='https://www.microsoftedgeinsider.com/en-us/download/canary'>Edge Canary</a>." ;
87
+ webgpuSupportMessage . classList . add ( 'red' ) ;
77
88
console . error ( "WebGPU is not supported" ) ;
78
89
} else {
79
90
webgpuSupportMessage . innerHTML = "WebGPU is supported in your browser!" ;
91
+ webgpuSupportMessage . classList . add ( 'green' ) ;
80
92
setModelButtonDisabled ( false ) ;
81
93
}
82
94
@@ -98,13 +110,14 @@ <h1>WebGPU GPT Model Demo</h1>
98
110
setTextareaDisabled ( false ) ;
99
111
}
100
112
101
- async function loadModel ( folder , tokenizer ) {
113
+ async function loadModel ( folder , tokenizer , buttonEl ) {
102
114
setModelButtonDisabled ( true ) ;
103
115
116
+ buttonEl . classList . add ( 'loading' ) ;
104
117
GPTModel = new GPT ( folder , tokenizer ) ;
105
118
await GPTModel . initialize ( ) ;
106
119
107
-
120
+ buttonEl . classList . remove ( 'loading' ) ;
108
121
promptTextarea . value = GPTModel . defaultPrompt ;
109
122
topKInput . value = GPTModel . defaultTopK ;
110
123
tokensInput . value = GPTModel . defaultTokens ;
0 commit comments