|
1 | 1 | # llm.cs - C# port of @karpathy [llm.c](https://github.com/karpathy/llm.c)
|
2 |
| - |
| 2 | + |
3 | 3 | 
|
4 |
| - |
5 |
| -[](https://github.com/nietras/Llm/actions/workflows/dotnet.yml) |
6 |
| -[](https://github.com/marketplace/actions/super-linter) |
7 |
| -[](https://codecov.io/gh/nietras/Llm) |
8 |
| -[](https://github.com/nietras/Llm/actions?query=workflow%3ACodeQL) |
| 4 | + |
| 5 | +[](https://github.com/nietras/llm.cs/actions/workflows/dotnet.yml) |
| 6 | +[](https://github.com/marketplace/actions/super-linter) |
| 7 | +[](https://codecov.io/gh/nietras/llm.cs) |
| 8 | +[](https://github.com/nietras/llm.cs/actions?query=workflow%3ACodeQL) |
9 | 9 | [](https://www.nuget.org/packages/Llm/)
|
10 |
| -[](https://github.com/nietras/Llm/releases/) |
| 10 | +[](https://github.com/nietras/llm.cs/releases/) |
11 | 11 | [](https://www.nuget.org/packages/Llm)
|
12 |
| - |
13 |
| -[](https://github.com/nietras/Llm/blob/main/LICENSE) |
| 12 | + |
| 13 | +[](https://github.com/nietras/llm.cs/blob/main/LICENSE) |
14 | 14 | [](https://nietras.com)
|
15 | 15 |
|
16 | 16 | ⭐ Please star this project if you like it. ⭐
|
|
33 | 33 | [assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v8.0", FrameworkDisplayName=".NET 8.0")]
|
34 | 34 | namespace nietras.LargeLanguageModel
|
35 | 35 | {
|
36 |
| - public static class Llm { } |
| 36 | + public static class Gpt2 |
| 37 | + { |
| 38 | + public static void Train() { } |
| 39 | + public static unsafe void attention_backward(float* dinp, float* dpreatt, float* datt, float* dout, float* inp, float* att, int B, int T, int C, int NH) { } |
| 40 | + public static unsafe void attention_forward(float* output, float* preatt, float* att, float* inp, int B, int T, int C, int NH) { } |
| 41 | + public static unsafe T* calloc<T>(long size) |
| 42 | + where T : unmanaged { } |
| 43 | + public static unsafe void crossentropy_forward(float* losses, float* probs, int* targets, int B, int T, int V) { } |
| 44 | + public static unsafe void crossentropy_softmax_backward(float* dlogits, float* dlosses, float* probs, int* targets, int B, int T, int V) { } |
| 45 | + public static unsafe void encoder_backward(float* dwte, float* dwpe, float* dout, int* inp, int B, int T, int C) { } |
| 46 | + public static unsafe void encoder_forward(float* output, int* inp, float* wte, float* wpe, int B, int T, int C) { } |
| 47 | + public static unsafe void free<T>(T* ptr) |
| 48 | + where T : unmanaged { } |
| 49 | + public static unsafe void gelu_backward(float* dinp, float* inp, float* dout, int N) { } |
| 50 | + public static unsafe void gelu_forward(float* output, float* inp, int N) { } |
| 51 | + public static unsafe void gpt2_build_from_checkpoint(nietras.LargeLanguageModel.Gpt2.GPT2* model, string checkpoint_path) { } |
| 52 | + public static unsafe void layernorm_backward(float* dinp, float* dweight, float* dbias, float* dout, float* inp, float* weight, float* mean, float* rstd, int B, int T, int C) { } |
| 53 | + public static unsafe void layernorm_forward(float* output, float* mean, float* rstd, float* inp, float* weight, float* bias, int B, int T, int C) { } |
| 54 | + public static unsafe T* malloc<T>(long size) |
| 55 | + where T : unmanaged { } |
| 56 | + public static unsafe float* malloc_and_point_activations(nietras.LargeLanguageModel.Gpt2.ActivationTensors* acts, long* act_sizes) { } |
| 57 | + public static unsafe float* malloc_and_point_parameters(nietras.LargeLanguageModel.Gpt2.ParameterTensors* parameters, long* param_sizes) { } |
| 58 | + public static unsafe void matmul_backward(float* dinp, float* dweight, float* dbias, float* dout, float* inp, float* weight, int B, int T, int C, int OC) { } |
| 59 | + public static unsafe void matmul_forward(float* output, float* inp, float* weight, float* bias, int B, int T, int C, int OC) { } |
| 60 | + public static unsafe void memcpy<T>(T* dest, T* src, long size) |
| 61 | + where T : unmanaged { } |
| 62 | + public static unsafe void memset<T>(T* ptr, long size) |
| 63 | + where T : unmanaged { } |
| 64 | + public static unsafe void residual_backward(float* dinp1, float* dinp2, float* dout, int N) { } |
| 65 | + public static unsafe void residual_forward(float* output, float* inp1, float* inp2, int N) { } |
| 66 | + public static unsafe void softmax_forward(float* probs, float* logits, int B, int T, int V) { } |
| 67 | + public struct ActivationTensors |
| 68 | + { |
| 69 | + public unsafe float* att; |
| 70 | + public unsafe float* attproj; |
| 71 | + public unsafe float* atty; |
| 72 | + public unsafe float* encoded; |
| 73 | + public unsafe float* fch; |
| 74 | + public unsafe float* fch_gelu; |
| 75 | + public unsafe float* fcproj; |
| 76 | + public unsafe float* ln1; |
| 77 | + public unsafe float* ln1_mean; |
| 78 | + public unsafe float* ln1_rstd; |
| 79 | + public unsafe float* ln2; |
| 80 | + public unsafe float* ln2_mean; |
| 81 | + public unsafe float* ln2_rstd; |
| 82 | + public unsafe float* lnf; |
| 83 | + public unsafe float* lnf_mean; |
| 84 | + public unsafe float* lnf_rstd; |
| 85 | + public unsafe float* logits; |
| 86 | + public unsafe float* losses; |
| 87 | + public unsafe float* preatt; |
| 88 | + public unsafe float* probs; |
| 89 | + public unsafe float* qkv; |
| 90 | + public unsafe float* residual2; |
| 91 | + public unsafe float* residual3; |
| 92 | + } |
| 93 | + public class DataLoader : System.IDisposable |
| 94 | + { |
| 95 | + public int B; |
| 96 | + public int T; |
| 97 | + public unsafe int* batch; |
| 98 | + public long current_position; |
| 99 | + public long file_size; |
| 100 | + public unsafe int* inputs; |
| 101 | + public long num_batches; |
| 102 | + public unsafe int* targets; |
| 103 | + public System.IO.FileStream tokens_file; |
| 104 | + public DataLoader(string filename, int B, int T) { } |
| 105 | + public void Dispose() { } |
| 106 | + protected virtual void Dispose(bool disposing) { } |
| 107 | + public void dataloader_free() { } |
| 108 | + public void dataloader_next_batch() { } |
| 109 | + public void dataloader_reset() { } |
| 110 | + } |
| 111 | + public struct GPT2 |
| 112 | + { |
| 113 | + [System.Runtime.CompilerServices.FixedBuffer(typeof(long), 23)] |
| 114 | + public nietras.LargeLanguageModel.Gpt2.GPT2.<act_sizes>e__FixedBuffer act_sizes; |
| 115 | + public nietras.LargeLanguageModel.Gpt2.ActivationTensors acts; |
| 116 | + public unsafe float* acts_memory; |
| 117 | + public int batch_size; |
| 118 | + public nietras.LargeLanguageModel.Gpt2.GPT2Config config; |
| 119 | + public nietras.LargeLanguageModel.Gpt2.ParameterTensors grads; |
| 120 | + public nietras.LargeLanguageModel.Gpt2.ActivationTensors grads_acts; |
| 121 | + public unsafe float* grads_acts_memory; |
| 122 | + public unsafe float* grads_memory; |
| 123 | + public unsafe int* inputs; |
| 124 | + public unsafe float* m_memory; |
| 125 | + public float mean_loss; |
| 126 | + public long num_activations; |
| 127 | + public long num_parameters; |
| 128 | + [System.Runtime.CompilerServices.FixedBuffer(typeof(long), 16)] |
| 129 | + public nietras.LargeLanguageModel.Gpt2.GPT2.<param_sizes>e__FixedBuffer param_sizes; |
| 130 | + public nietras.LargeLanguageModel.Gpt2.ParameterTensors parameters; |
| 131 | + public unsafe float* params_memory; |
| 132 | + public int seq_len; |
| 133 | + public unsafe int* targets; |
| 134 | + public unsafe float* v_memory; |
| 135 | + } |
| 136 | + public struct GPT2Config |
| 137 | + { |
| 138 | + public int channels; |
| 139 | + public int max_seq_len; |
| 140 | + public int num_heads; |
| 141 | + public int num_layers; |
| 142 | + public int vocab_size; |
| 143 | + } |
| 144 | + public struct ParameterTensors |
| 145 | + { |
| 146 | + public unsafe float* attprojb; |
| 147 | + public unsafe float* attprojw; |
| 148 | + public unsafe float* fcb; |
| 149 | + public unsafe float* fcprojb; |
| 150 | + public unsafe float* fcprojw; |
| 151 | + public unsafe float* fcw; |
| 152 | + public unsafe float* ln1b; |
| 153 | + public unsafe float* ln1w; |
| 154 | + public unsafe float* ln2b; |
| 155 | + public unsafe float* ln2w; |
| 156 | + public unsafe float* lnfb; |
| 157 | + public unsafe float* lnfw; |
| 158 | + public unsafe float* qkvb; |
| 159 | + public unsafe float* qkvw; |
| 160 | + public unsafe float* wpe; |
| 161 | + public unsafe float* wte; |
| 162 | + } |
| 163 | + } |
37 | 164 | }
|
38 | 165 | ```
|
0 commit comments