1+ #include "gpu.hpp"
2+ #ifdef __EMSCRIPTEN__
3+ #include "unittest_kernels.h" // replace once we figure out how to get context to persist
4+ #else
15#include "ops.hpp"
6+ #endif
27/*
38This file trains the GPT-2 model.
49This version is the clean, minimal, reference. As such:
@@ -18,6 +23,7 @@ There will be other versions of this code that specialize it and make it fast.
1823#include <time.h>
1924#include <string.h>
2025#include <unistd.h>
26+ #include <memory>
2127#ifdef OMP
2228#include <omp.h>
2329#endif
@@ -722,8 +728,11 @@ void gpt2_build_from_checkpoint(GPT2 *model, const char* checkpoint_path) {
722728 size_t maxT , V , Vp , L , NH , C ; // size_t to prevent int overflow
723729 model -> config .max_seq_len = maxT = model_header [2 ];
724730 model -> config .vocab_size = V = model_header [3 ];
725- // model->config.num_layers = L = model_header[4];
726- model -> config .num_layers = L = 3 ; // TODO(avh): Debugging only hack - revert this
731+ #ifdef __EMSCRIPTEN__
732+ model -> config .num_layers = L = 12 ; // TODO(avh): Debugging only hack - revert this
733+ #else
734+ model -> config .num_layers = L = model_header [4 ];
735+ #endif
727736 model -> config .num_heads = NH = model_header [5 ];
728737 model -> config .channels = C = model_header [6 ];
729738 model -> config .padded_vocab_size = Vp = model_header [7 ];
@@ -827,6 +836,7 @@ void gpt2_forward(GPT2 *model, int* inputs, int* targets, size_t B, size_t T) {
827836 ParameterTensors params = model -> params ; // for brevity
828837 ActivationTensors acts = model -> acts ;
829838 float * residual ;
839+ printf ("Encoding\n" );
830840 encoder_forward (acts .encoded , inputs , params .wte , params .wpe , B , T , C ); // encoding goes into residual[0]
831841 for (int l = 0 ; l < L ; l ++ ) {
832842 printf ("Forward Pass Layer %d\n" , l );
@@ -1106,7 +1116,6 @@ int sample_mult(float* probabilities, int n, float coin) {
11061116// ----------------------------------------------------------------------------
11071117// main training loop
11081118int main () {
1109- initRuntime ();
11101119
11111120 // build the GPT-2 model from a checkpoint
11121121 GPT2 model ;
@@ -1137,9 +1146,22 @@ int main() {
11371146 int * gen_tokens = (int * )mallocCheck (B * T * sizeof (int ));
11381147 const int genT = 64 ; // number of steps of inference we will do
11391148
1149+ #ifdef __EMSCRIPTEN__
1150+ #else
1151+ printf ("Creating GPU context\n" );
1152+ WGPURequiredLimits requiredLimits = LIMITS_BUFFER_SIZE_1GB ;
1153+ kCtx = static_cast < gpu ::Context * > (mallocCheck (sizeof (gpu ::Context ) * 32 ));
1154+ * kCtx = gpu ::createContext ({}, {}, {
1155+ .requiredLimits = & requiredLimits
1156+ });
1157+ printf ("GPU context created\n" );
1158+ #endif
1159+
11401160 // train
11411161 struct timespec start , end ;
1162+ printf ("Starting training\n" );
11421163 for (int step = 0 ; step <= 40 ; step ++ ) {
1164+ printf ("Step %d\n" , step );
11431165
11441166 // once in a while estimate the validation loss
11451167 if (step % 10 == 0 ) {
0 commit comments