Loading the rest of this comparison.

What changes here?

Created Diff never expires
20 removals
538 lines
13 additions
535 lines
/*
/*
Version 2 of the code, removing bias from forward pass
Version 2 of the code, removing bias from forward pass
*/
*/


#include <unistd.h>
#include <unistd.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdarg.h>
#include <string>
#include <string>
#include <string_view>
#include <string_view>
#include <sys/stat.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/types.h>
// ----------- CPU utilities -----------
// ----------- CPU utilities -----------
// defines: fopenCheck, freadCheck, fcloseCheck, fseekCheck, mallocCheck
// defines: fopenCheck, freadCheck, fcloseCheck, fseekCheck, mallocCheck
// defines: create_dir_if_not_exists, find_max_step, ends_with_bin
// defines: create_dir_if_not_exists, find_max_step, ends_with_bin
#include "llmc/utils.h"
#include "llmc/utils.h"
// defines: tokenizer_init, tokenizer_decode, tokenizer_free
// defines: tokenizer_init, tokenizer_decode, tokenizer_free
#include "llmc/tokenizer.h"
#include "llmc/tokenizer.h"
// defines: dataloader_init, dataloader_reset, dataloader_next_batch, dataloader_free
// defines: dataloader_init, dataloader_reset, dataloader_next_batch, dataloader_free
// defines: evalloader_init, evalloader_reset, evalloader_next_batch, evalloader_free
// defines: evalloader_init, evalloader_reset, evalloader_next_batch, evalloader_free
#include "llmc/dataloader.h"
#include "llmc/dataloader.h"
// defines: manual_seed, normal_ (same as torch.manual_seed and torch.normal)
// defines: manual_seed, normal_ (same as torch.manual_seed and torch.normal)
#include "llmc/rand.h"
#include "llmc/rand.h"
// defines: lr_scheduler_init, get_learning_rate
// defines: lr_scheduler_init, get_learning_rate
#include "llmc/schedulers.h"
#include "llmc/schedulers.h"
// defines: sample_softmax, random_f32
// defines: sample_softmax, random_f32
#include "llmc/sampler.h"
#include "llmc/sampler.h"
// defines: logger_init, logger_log_eval, logger_log_val, logger_log_train
// defines: logger_init, logger_log_eval, logger_log_val, logger_log_train
#include "llmc/logger.h"
#include "llmc/logger.h"
// defines: get_flops_promised
// defines: get_flops_promised
#include "llmc/mfu.h"
#include "llmc/mfu.h"
// defines: OutlierDetector, init_detector, update_detector
// defines: OutlierDetector, init_detector, update_detector
#include "llmc/outlier_detector.h"
#include "llmc/outlier_detector.h"
// ----------- GPU utilities -----------
// ----------- GPU utilities -----------
// defines:
// defines:
// WARP_SIZE, MAX_1024_THREADS_BLOCKS, CEIL_DIV, cudaCheck, PRECISION_MODE
// WARP_SIZE, MAX_1024_THREADS_BLOCKS, CEIL_DIV, cudaCheck, PRECISION_MODE
// NVTX_RANGE_FN
// NVTX_RANGE_FN
#include "llmc/cuda_common.h"
#include "llmc/cuda_common.h"
// defines:
// defines:
// Packed128, f128, x128
// Packed128, f128, x128
// warpReduceSum, warpReduceMax, blockReduce, copy_and_cast_kernel, cudaMallocConditionallyManaged
// warpReduceSum, warpReduceMax, blockReduce, copy_and_cast_kernel, cudaMallocConditionallyManaged
#include "llmc/cuda_utils.cuh"
#include "llmc/cuda_utils.cuh"
// defines: CUBLAS_LOWP, cublasCheck, cublaslt_workspace_size, cublaslt_workspace
// defines: CUBLAS_LOWP, cublasCheck, cublaslt_workspace_size, cublaslt_workspace
// defines: cublas_compute, cublaslt_handle, cublas_handle
// defines: cublas_compute, cublaslt_handle, cublas_handle
#include "llmc/cublas_common.h"
#include "llmc/cublas_common.h"
// ----------- Layer implementations in CUDA -----------
// ----------- Layer implementations in CUDA -----------
// defines: encoder_forward, encoder_backward
// defines: encoder_forward, encoder_backward
#include "llmc/encoder.cuh"
#include "llmc/encoder.cuh"
// defines: layernorm_forward, residual_forward, fused_residual_forward5, layernorm_backward
// defines: layernorm_forward, residual_forward, fused_residual_forward5, layernorm_backward
#include "llmc/layernorm.cuh"
#include "llmc/layernorm.cuh"
// defines: matmul_cublaslt, matmul_forward, matmul_backward, gelu_forward, gelu_backward_inplace
// defines: matmul_cublaslt, matmul_forward, matmul_backward, gelu_forward, gelu_backward_inplace
#include "llmc/matmul.cuh"
#include "llmc/matmul.cuh"
#ifdef ENABLE_CUDNN
#ifdef ENABLE_CUDNN
// defines: create_cudnn, destroy_cudnn, attention_forward_cudnn, attention_backward_cudnn
// defines: create_cudnn, destroy_cudnn, attention_forward_cudnn, attention_backward_cudnn
#include "llmc/cudnn_att.h"
#include "llmc/cudnn_att.h"
#else
#else
// defines: attention_forward, attention_backward
// defines: attention_forward, attention_backward
#include "llmc/attention.cuh"
#include "llmc/attention.cuh"
#endif
#endif
// defines: fused_classifier
// defines: fused_classifier
#include "llmc/fused_classifier.cuh"
#include "llmc/fused_classifier.cuh"
// defines: adamw_kernel3
// defines: adamw_kernel3
#include "llmc/adamw.cuh"
#include "llmc/adamw.cuh"
// defines: global_norm_squared
// defines: global_norm_squared
#include "llmc/global_norm.cuh"
#include "llmc/global_norm.cuh"
// ----------- Multi-GPU support -----------
// ----------- Multi-GPU support -----------
// defines: ncclFloatX, ncclCheck, MultiGpuConfig, ShardInfo
// defines: ncclFloatX, ncclCheck, MultiGpuConfig, ShardInfo
// defines: printf0, multi_gpu_config
// defines: printf0, multi_gpu_config
// defines: multi_gpu_config_init, multi_gpu_config_free
// defines: multi_gpu_config_init, multi_gpu_config_free
// defines: set_zero_configs, multi_gpu_cpu_float_sum, multi_gpu_barrier
// defines: set_zero_configs, multi_gpu_cpu_float_sum, multi_gpu_barrier
// defines: multi_gpu_get_shard_offset, multi_gpu_async_reduce_gradient
// defines: multi_gpu_get_shard_offset, multi_gpu_async_reduce_gradient
#include "llmc/zero.cuh"
#include "llmc/zero.cuh"


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// global vars for I/O
// global vars for I/O
char filename_buffer[512];
char filename_buffer[512];


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// global vars containing information about the GPU this process is running on
// global vars containing information about the GPU this process is running on
cudaDeviceProp deviceProp; // fills in common_start()
cudaDeviceProp deviceProp; // fills in common_start()
cudaStream_t main_stream;
cudaStream_t main_stream;
// buffer size to use for device <-> disk io
// buffer size to use for device <-> disk io
constexpr const size_t IO_BUF_SIZE = 32 * 1024 * 1024;
constexpr const size_t IO_BUF_SIZE = 32 * 1024 * 1024;


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// GPT-2 model definition
// GPT-2 model definition


typedef struct {
typedef struct {
int max_seq_len; // max sequence length, e.g. 1024
int max_seq_len; // max sequence length, e.g. 1024
int vocab_size; // vocab size, e.g. 50257
int vocab_size; // vocab size, e.g. 50257
int padded_vocab_size; // padded to e.g. %128==0, 50304
int padded_vocab_size; // padded to e.g. %128==0, 50304
int num_layers; // number of layers, e.g. 12
int num_layers; // number of layers, e.g. 12
int num_heads; // number of heads in attention, e.g. 12
int num_heads; // number of heads in attention, e.g. 12
int channels; // number of channels, e.g. 768
int channels; // number of channels, e.g. 768
} GPTConfig;
} GPTConfig;


// the parameters of the model
// the parameters of the model
constexpr const int NUM_PARAMETER_TENSORS = 16;
constexpr const int NUM_PARAMETER_TENSORS = 12;
typedef struct {
typedef struct {
floatX* wte; // (V, C)
floatX* wte; // (V, C)