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 ="globals.js "> </ script >
13
14
</ head >
14
15
< body >
15
- < h1 > WebGPU GPT Model Demo</ h1 >
16
- < p id ="webgpuSupportMessage "> Checking WebGPU support...</ p >
17
- < p >
18
- < 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 >
19
- </ p >
20
-
21
- < button class ="loadModelButton " onclick ="loadModel('better_shakespeare', 'char') " disabled > Load Shakespeare Model</ button >
22
- < button class ="loadModelButton " onclick ="loadModel('gpt2', 'bpe') " disabled > Load GPT2 117M Model</ button >
23
- < button id ="destroyCacheButton " onclick ="destroyCache() " disabled > Destroy Cache</ button >
24
-
25
- < p >
26
- < i > Special models (download required):</ i >
27
- </ p >
28
- < button class ="loadModelButton " onclick ="loadModel('large-models/gpt2-medium', 'bpe') " disabled > Load GPT2 377M Model</ button >
29
- < button class ="loadModelButton " onclick ="loadModel('large-models/gpt2-large', 'bpe') " disabled > Load GPT2 777M Model</ button >
30
- < button class ="loadModelButton " onclick ="loadModel('large-models/gpt2-xl', 'bpe') " disabled > Load GPT2 1.5B Model</ button >
31
-
32
- < br />
33
- < br />
34
- < label for ="tokens "> Number of tokens:</ label >
35
- < input type ="number " min ="1 " max ="300 " value ="100 " id ="tokensInput " disabled />
36
- < br /> < br />
37
- < label for ="topK "> Top K:</ label >
38
- < input type ="number " min ="1 " max ="100 " value ="2 " id ="topKInput " disabled />
39
- < br /> < br />
40
- < label for ="temperature "> Temperature:</ label >
41
- < input type ="number " step ="0.01 " min ="0.1 " max ="2 " value ="1 " id ="temperatureInput " disabled />
42
- < br /> < br />
43
- < button id ="generateButton " onclick ="startGeneration() " disabled > Generate Text</ button >
44
- < br /> < br />
45
- < textarea id ="prompt " rows ="15 " cols ="50 " disabled >
16
+ < div class ="container ">
17
+
18
+ < h1 > WebGPU GPT Model Demo</ h1 >
19
+ < h3 id ="webgpuSupportMessage " class ="support-message "> Checking WebGPU support...</ h3 >
20
+ < p >
21
+ < 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 >
22
+ </ p >
23
+
24
+ < button class ="loadModelButton " onclick ="loadModel('better_shakespeare', 'char', this) " disabled >
25
+ < span class ="button-text "> Load Shakespeare Model</ span >
26
+ </ button >
27
+ < button class ="loadModelButton " onclick ="loadModel('gpt2', 'bpe', this) " disabled >
28
+ < span class ="button-text "> Load GPT2 117M Model</ span >
29
+ </ button >
30
+ < button id ="destroyCacheButton " onclick ="destroyCache() " disabled > Destroy Cache</ button >
31
+
32
+ < p >
33
+ < i > Special models (download required):</ i >
34
+ </ p >
35
+ < button class ="loadModelButton " onclick ="loadModel('large-models/gpt2-medium', 'bpe', this) " disabled >
36
+ < span class ="button-text "> Load GPT2 377M Model</ span >
37
+ </ button >
38
+ < button class ="loadModelButton " onclick ="loadModel('large-models/gpt2-large', 'bpe', this) " disabled >
39
+ < span class ="button-text "> Load GPT2 777M Model</ span >
40
+ </ button >
41
+ < button class ="loadModelButton " onclick ="loadModel('large-models/gpt2-xl', 'bpe', this) " disabled >
42
+ < span class ="button-text "> Load GPT2 1.5B Model</ span >
43
+ </ button >
44
+
45
+ < div >
46
+ < button id ="generateButton " onclick ="startGeneration() " disabled > Generate Text</ button >
47
+ < label for ="tokens "> Number of tokens:</ label >
48
+ < input type ="number " min ="1 " max ="300 " value ="100 " id ="tokensInput " disabled />
49
+ < label for ="topK "> Top K:</ label >
50
+ < input type ="number " min ="1 " max ="100 " value ="2 " id ="topKInput " disabled />
51
+ < label for ="temperature "> Temperature:</ label >
52
+ < input type ="number " step ="0.01 " min ="0.1 " max ="2 " value ="1 " id ="temperatureInput " disabled />
53
+ < textarea class ="prompt " id ="prompt " rows ="15 " cols ="50 " disabled >
46
54
WILL:
47
55
Ah, how dare you challenge me?
48
- Have you forgotten I built WebGPT? </ textarea
49
- >
50
- < br /> < br />
56
+ Have you forgotten I built WebGPT?
57
+ </ textarea >
58
+ </ div >
59
+ </ div >
51
60
< script >
52
61
const webgpuSupportMessage = document . getElementById ( "webgpuSupportMessage" ) ;
53
62
const loadModelButton = document . getElementsByClassName ( "loadModelButton" ) ;
@@ -68,9 +77,11 @@ <h1>WebGPU GPT Model Demo</h1>
68
77
if ( ! navigator . gpu ) {
69
78
webgpuSupportMessage . innerHTML =
70
79
"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>." ;
80
+ webgpuSupportMessage . classList . add ( 'red' ) ;
71
81
console . error ( "WebGPU is not supported" ) ;
72
82
} else {
73
83
webgpuSupportMessage . innerHTML = "WebGPU is supported in your browser!" ;
84
+ webgpuSupportMessage . classList . add ( 'green' ) ;
74
85
setModelButtonDisabled ( false ) ;
75
86
}
76
87
@@ -91,12 +102,14 @@ <h1>WebGPU GPT Model Demo</h1>
91
102
setTextareaDisabled ( false ) ;
92
103
}
93
104
94
- async function loadModel ( folder , tokenizer ) {
105
+ async function loadModel ( folder , tokenizer , buttonEl ) {
95
106
setModelButtonDisabled ( true ) ;
96
107
108
+ buttonEl . classList . add ( 'loading' ) ;
97
109
GPTModel = new GPT ( folder , tokenizer ) ;
98
110
await GPTModel . initialize ( ) ;
99
111
112
+ buttonEl . classList . remove ( 'loading' ) ;
100
113
promptTextarea . value = GPTModel . defaultPrompt ;
101
114
topKInput . value = GPTModel . defaultTopK ;
102
115
tokensInput . value = GPTModel . defaultTokens ;
0 commit comments