#include <stdio.h>
#include <stdlib.h>
-#include <assert.h>
int main(int argc, const char ** argv) {
struct ggml_init_params params = {
printf("f = %f\n", ggml_get_f32_1d(f, 0));
printf("df/dx = %f\n", ggml_get_f32_1d(x->grad, 0));
- assert(ggml_get_f32_1d(f, 0) == 12.0f);
- assert(ggml_get_f32_1d(x->grad, 0) == 12.0f);
+ GGML_ASSERT(ggml_get_f32_1d(f, 0) == 12.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x->grad, 0) == 12.0f);
ggml_set_f32(x, 3.0f);
printf("f = %f\n", ggml_get_f32_1d(f, 0));
printf("df/dx = %f\n", ggml_get_f32_1d(x->grad, 0));
- assert(ggml_get_f32_1d(f, 0) == 27.0f);
- assert(ggml_get_f32_1d(x->grad, 0) == 18.0f);
+ GGML_ASSERT(ggml_get_f32_1d(f, 0) == 27.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x->grad, 0) == 18.0f);
ggml_graph_dump_dot(&gf, NULL, "test1-1-forward.dot");
ggml_graph_dump_dot(&gb, &gf, "test1-1-backward.dot");
printf("df/dx1 = %f\n", ggml_get_f32_1d(x1->grad, 0));
printf("df/dx2 = %f\n", ggml_get_f32_1d(x2->grad, 0));
- assert(ggml_get_f32_1d(y, 0) == 12.0f);
- assert(ggml_get_f32_1d(x1->grad, 0) == 7.0f);
- assert(ggml_get_f32_1d(x2->grad, 0) == 3.0f);
+ GGML_ASSERT(ggml_get_f32_1d(y, 0) == 12.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x1->grad, 0) == 7.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x2->grad, 0) == 3.0f);
struct ggml_tensor * g1 = x1->grad;
struct ggml_tensor * g2 = x2->grad;
printf("H * [1, 1] = [ %f %f ]\n", ggml_get_f32_1d(x1->grad, 0), ggml_get_f32_1d(x2->grad, 0));
- assert(ggml_get_f32_1d(x1->grad, 0) == 3.0f);
- assert(ggml_get_f32_1d(x2->grad, 0) == 1.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x1->grad, 0) == 3.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x2->grad, 0) == 1.0f);
ggml_graph_dump_dot(&gf, NULL, "test1-2-forward.dot");
ggml_graph_dump_dot(&gb, &gf, "test1-2-backward.dot");
printf("df/dx1 = %f\n", ggml_get_f32_1d(x1->grad, 0));
printf("df/dx2 = %f\n", ggml_get_f32_1d(x2->grad, 0));
- assert(ggml_get_f32_1d(y, 0) == 63.0f);
- assert(ggml_get_f32_1d(x1->grad, 0) == 51.0f);
- assert(ggml_get_f32_1d(x2->grad, 0) == 9.0f);
+ GGML_ASSERT(ggml_get_f32_1d(y, 0) == 63.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x1->grad, 0) == 51.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x2->grad, 0) == 9.0f);
ggml_graph_dump_dot(&gf, NULL, "test1-3-forward.dot");
ggml_graph_dump_dot(&gb, &gf, "test1-3-backward.dot");
printf("df/dx2 = %f\n", ggml_get_f32_1d(x2->grad, 0));
printf("df/dx3 = %f\n", ggml_get_f32_1d(x3->grad, 0));
- assert(ggml_get_f32_1d(y, 0) == 12.0f);
- assert(ggml_get_f32_1d(x1->grad, 0) == 24.0f);
- assert(ggml_get_f32_1d(x2->grad, 0) == 12.0f);
- assert(ggml_get_f32_1d(x3->grad, 0) == 4.0f);
+ GGML_ASSERT(ggml_get_f32_1d(y, 0) == 12.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x1->grad, 0) == 24.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x2->grad, 0) == 12.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x3->grad, 0) == 4.0f);
struct ggml_tensor * g1 = x1->grad;
struct ggml_tensor * g2 = x2->grad;
ggml_get_f32_1d(x2->grad, 0),
ggml_get_f32_1d(x3->grad, 0));
- assert(ggml_get_f32_1d(x1->grad, 0) == 56.0f);
- assert(ggml_get_f32_1d(x2->grad, 0) == 34.0f);
- assert(ggml_get_f32_1d(x3->grad, 0) == 12.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x1->grad, 0) == 56.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x2->grad, 0) == 34.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x3->grad, 0) == 12.0f);
ggml_graph_dump_dot(&gf, NULL, "test1-4-forward.dot");
ggml_graph_dump_dot(&gb, &gf, "test1-4-backward.dot");
ggml_get_f32_1d(x2->grad, 1),
ggml_get_f32_1d(x2->grad, 2));
- assert(ggml_get_f32_1d(y, 0) == 45.0f);
- assert(ggml_get_f32_1d(x1->grad, 0) == 5.0f);
- assert(ggml_get_f32_1d(x2->grad, 0) == 3.0f);
- assert(ggml_get_f32_1d(x1->grad, 1) == 5.0f);
- assert(ggml_get_f32_1d(x2->grad, 1) == 3.0f);
- assert(ggml_get_f32_1d(x1->grad, 2) == 5.0f);
- assert(ggml_get_f32_1d(x2->grad, 2) == 3.0f);
+ GGML_ASSERT(ggml_get_f32_1d(y, 0) == 45.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x1->grad, 0) == 5.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x2->grad, 0) == 3.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x1->grad, 1) == 5.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x2->grad, 1) == 3.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x1->grad, 2) == 5.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x2->grad, 2) == 3.0f);
ggml_graph_dump_dot(&gf, NULL, "test1-5-forward.dot");
ggml_graph_dump_dot(&gb, &gf, "test1-5-backward.dot");
ggml_get_f32_1d(x2->grad, 1),
ggml_get_f32_1d(x2->grad, 2));
- assert(ggml_get_f32_1d(y, 0) == -9.0f);
- assert(ggml_get_f32_1d(x1->grad, 0) == -7.0f);
- assert(ggml_get_f32_1d(x1->grad, 1) == -7.0f);
- assert(ggml_get_f32_1d(x1->grad, 2) == -7.0f);
- assert(ggml_get_f32_1d(x2->grad, 0) == 3.0f);
- assert(ggml_get_f32_1d(x2->grad, 1) == 3.0f);
- assert(ggml_get_f32_1d(x2->grad, 2) == 3.0f);
+ GGML_ASSERT(ggml_get_f32_1d(y, 0) == -9.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x1->grad, 0) == -7.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x1->grad, 1) == -7.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x1->grad, 2) == -7.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x2->grad, 0) == 3.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x2->grad, 1) == 3.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x2->grad, 2) == 3.0f);
ggml_graph_dump_dot(&gf, NULL, "test1-6-forward.dot");
ggml_graph_dump_dot(&gb, &gf, "test1-6-backward.dot");
ggml_get_f32_1d(x2->grad, 1),
ggml_get_f32_1d(x2->grad, 2));
- assert(ggml_get_f32_1d(y, 0) == 99.0f);
- assert(ggml_get_f32_1d(x1->grad, 0) == 17.0f);
- assert(ggml_get_f32_1d(x1->grad, 1) == 17.0f);
- assert(ggml_get_f32_1d(x1->grad, 2) == 17.0f);
- assert(ggml_get_f32_1d(x2->grad, 0) == 3.0f);
- assert(ggml_get_f32_1d(x2->grad, 1) == 3.0f);
- assert(ggml_get_f32_1d(x2->grad, 2) == 3.0f);
+ GGML_ASSERT(ggml_get_f32_1d(y, 0) == 99.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x1->grad, 0) == 17.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x1->grad, 1) == 17.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x1->grad, 2) == 17.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x2->grad, 0) == 3.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x2->grad, 1) == 3.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x2->grad, 2) == 3.0f);
ggml_graph_dump_dot(&gf, NULL, "test1-7-forward.dot");
ggml_graph_dump_dot(&gb, &gf, "test1-7-backward.dot");
ggml_get_f32_1d(x2->grad, 1),
ggml_get_f32_1d(x2->grad, 2));
- assert(ggml_get_f32_1d(y, 0) == 2.0f);
- assert(ggml_get_f32_1d(x1->grad, 0) == -1.0f);
- assert(ggml_get_f32_1d(x1->grad, 1) == -1.0f);
- assert(ggml_get_f32_1d(x1->grad, 2) == -1.0f);
- assert(ggml_get_f32_1d(x2->grad, 0) == 1.0f);
- assert(ggml_get_f32_1d(x2->grad, 1) == 1.0f);
- assert(ggml_get_f32_1d(x2->grad, 2) == 1.0f);
+ GGML_ASSERT(ggml_get_f32_1d(y, 0) == 2.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x1->grad, 0) == -1.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x1->grad, 1) == -1.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x1->grad, 2) == -1.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x2->grad, 0) == 1.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x2->grad, 1) == 1.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x2->grad, 2) == 1.0f);
ggml_set_f32(x1, 7.0f);
ggml_set_f32(x2, 5.0f);
ggml_get_f32_1d(x2->grad, 1),
ggml_get_f32_1d(x2->grad, 2));
- assert(ggml_get_f32_1d(y, 0) == 2.0f);
- assert(ggml_get_f32_1d(x1->grad, 0) == 1.0f);
- assert(ggml_get_f32_1d(x1->grad, 1) == 1.0f);
- assert(ggml_get_f32_1d(x1->grad, 2) == 1.0f);
- assert(ggml_get_f32_1d(x2->grad, 0) == -1.0f);
- assert(ggml_get_f32_1d(x2->grad, 1) == -1.0f);
- assert(ggml_get_f32_1d(x2->grad, 2) == -1.0f);
+ GGML_ASSERT(ggml_get_f32_1d(y, 0) == 2.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x1->grad, 0) == 1.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x1->grad, 1) == 1.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x1->grad, 2) == 1.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x2->grad, 0) == -1.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x2->grad, 1) == -1.0f);
+ GGML_ASSERT(ggml_get_f32_1d(x2->grad, 2) == -1.0f);
ggml_graph_dump_dot(&gf, NULL, "test1-8-forward.dot");
ggml_graph_dump_dot(&gb, &gf, "test1-8-backward.dot");
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
-#include <assert.h>
bool is_close(float a, float b, float epsilon) {
return fabs(a - b) < epsilon;
.no_alloc = false,
};
- //struct ggml_opt_params opt_params = ggml_opt_default_params(GGML_OPT_LBFGS);
+ //struct ggml_opt_params opt_params = ggml_opt_default_params(GGML_OPT_ADAM);
+ //opt_params.adam.alpha = 0.01f;
- struct ggml_opt_params opt_params = ggml_opt_default_params(GGML_OPT_ADAM);
- opt_params.adam.alpha = 0.01f;
+ struct ggml_opt_params opt_params = ggml_opt_default_params(GGML_OPT_LBFGS);
// original threads: 8
int nthreads = 8;
enum ggml_opt_result res = ggml_opt(NULL, opt_params, f);
- assert(res == GGML_OPT_OK);
-
printf("t0 = %f\n", ggml_get_f32_1d(t0, 0));
printf("t1 = %f\n", ggml_get_f32_1d(t1, 0));
- assert(is_close(ggml_get_f32_1d(t0, 0), 5.0f, 1e-3f));
- assert(is_close(ggml_get_f32_1d(t1, 0), 10.0f, 1e-3f));
+ GGML_ASSERT(res == GGML_OPT_OK);
+
+ GGML_ASSERT(is_close(ggml_get_f32_1d(t0, 0), 5.0f, 1e-3f));
+ GGML_ASSERT(is_close(ggml_get_f32_1d(t1, 0), 10.0f, 1e-3f));
}
{
enum ggml_opt_result res = ggml_opt(NULL, opt_params, f);
- assert(res == GGML_OPT_OK);
- assert(is_close(ggml_get_f32_1d(t0, 0), 5.0f, 1e-2f));
- assert(is_close(ggml_get_f32_1d(t1, 0), 10.0f, 1e-2f));
+ GGML_ASSERT(res == GGML_OPT_OK);
+ GGML_ASSERT(is_close(ggml_get_f32_1d(t0, 0), 5.0f, 1e-2f));
+ GGML_ASSERT(is_close(ggml_get_f32_1d(t1, 0), 10.0f, 1e-2f));
}
{
enum ggml_opt_result res = ggml_opt(NULL, opt_params, f);
- assert(res == GGML_OPT_OK);
- assert(is_close(ggml_get_f32_1d(f, 0), 0.0f, 1e-3f));
- assert(is_close(ggml_get_f32_1d(t0, 0), 0.0f, 1e-3f));
- assert(is_close(ggml_get_f32_1d(t1, 0), 0.0f, 1e-3f));
+ GGML_ASSERT(res == GGML_OPT_OK);
+ GGML_ASSERT(is_close(ggml_get_f32_1d(f, 0), 0.0f, 1e-3f));
+ GGML_ASSERT(is_close(ggml_get_f32_1d(t0, 0), 0.0f, 1e-3f));
+ GGML_ASSERT(is_close(ggml_get_f32_1d(t1, 0), 0.0f, 1e-3f));
}
/////////////////////////////////////////
enum ggml_opt_result res = ggml_opt(NULL, opt_params, f);
- assert(res == GGML_OPT_OK);
- assert(is_close(ggml_get_f32_1d(f, 0), 0.0f, 1e-3f));
- assert(is_close(ggml_get_f32_1d(t0, 0), 1.0f, 1e-3f));
- assert(is_close(ggml_get_f32_1d(t1, 0), 3.0f, 1e-3f));
+ GGML_ASSERT(res == GGML_OPT_OK);
+ GGML_ASSERT(is_close(ggml_get_f32_1d(f, 0), 0.0f, 1e-3f));
+ GGML_ASSERT(is_close(ggml_get_f32_1d(t0, 0), 1.0f, 1e-3f));
+ GGML_ASSERT(is_close(ggml_get_f32_1d(t1, 0), 3.0f, 1e-3f));
}
ggml_free(ctx0);