allocate memory for the parameters and point the individual tensors to the right places
| 91 | |
| 92 | // allocate memory for the parameters and point the individual tensors to the right places |
| 93 | float* malloc_and_point_parameters(ParameterTensors* params, size_t* param_sizes) { |
| 94 | size_t num_parameters = 0; |
| 95 | for (size_t i = 0; i < NUM_PARAMETER_TENSORS; i++) { |
| 96 | num_parameters += param_sizes[i]; |
| 97 | } |
| 98 | // malloc all parameters all at once |
| 99 | float* params_memory = (float*)mallocCheck(num_parameters * sizeof(float)); |
| 100 | // assign all the tensors |
| 101 | float** ptrs[] = { |
| 102 | ¶ms->wte, ¶ms->wpe, ¶ms->ln1w, ¶ms->ln1b, ¶ms->qkvw, ¶ms->qkvb, |
| 103 | ¶ms->attprojw, ¶ms->attprojb, ¶ms->ln2w, ¶ms->ln2b, ¶ms->fcw, ¶ms->fcb, |
| 104 | ¶ms->fcprojw, ¶ms->fcprojb, ¶ms->lnfw, ¶ms->lnfb |
| 105 | }; |
| 106 | float* params_memory_iterator = params_memory; |
| 107 | for (size_t i = 0; i < NUM_PARAMETER_TENSORS; i++) { |
| 108 | *(ptrs[i]) = params_memory_iterator; |
| 109 | params_memory_iterator += param_sizes[i]; |
| 110 | } |
| 111 | return params_memory; |
| 112 | } |
| 113 | |
| 114 | |
| 115 | #define NUM_ACTIVATION_TENSORS 23 |
no outgoing calls
no test coverage detected