interplane.Get Omega
Read in your language

ggml

[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)

Brought by drakestapleton

branch master Branches Tags History

ggml / examples / mnist / mnist-train.cpp

39 lines · 1434 bytes Raw Blame History
1#include "ggml-opt.h"
2#include "mnist-common.h"
3
4#include <cmath>
5#include <cstdio>
6#include <cstring>
7#include <ctime>
8#include <string>
9
10#if defined(_MSC_VER)
11#pragma warning(disable: 4244 4267) // possible loss of data
12#endif
13
14int main(int argc, char ** argv) {
15 if (argc != 5 && argc != 6) {
16 fprintf(stderr, "Usage: %s mnist-fc mnist-fc-f32.gguf data/MNIST/raw/train-images-idx3-ubyte data/MNIST/raw/train-labels-idx1-ubyte [CPU/CUDA0]\n", argv[0]);
17 exit(0);
18 }
19
20 // The MNIST model is so small that the overhead from data shuffling is non-negligible, especially with CUDA.
21 // With a shard size of 10 this overhead is greatly reduced at the cost of less shuffling (does not seem to have a significant impact).
22 // A batch of 500 images then consists of 50 random shards of size 10 instead of 500 random shards of size 1.
23 ggml_opt_dataset_t dataset = ggml_opt_dataset_init(GGML_TYPE_F32, GGML_TYPE_F32, MNIST_NINPUT, MNIST_NCLASSES, MNIST_NTRAIN, /*ndata_shard =*/ 10);
24
25 if (!mnist_image_load(argv[3], dataset)) {
26 return 1;
27 }
28 if (!mnist_label_load(argv[4], dataset)) {
29 return 1;
30 }
31
32 mnist_model model = mnist_model_init_random(argv[1], argc >= 6 ? argv[5] : "", MNIST_NBATCH_LOGICAL, MNIST_NBATCH_PHYSICAL);
33
34 mnist_model_build(model);
35
36 mnist_model_train(model, dataset, /*nepoch =*/ 30, /*val_split =*/ 0.05f);
37
38 mnist_model_save(model, argv[2]);
39}