TCL bindings for ggml , a tensor library for machine learning.
Contact: neophytos (at) gmail (dot) com
See example.tcl
package require ggml # create context set mem_size [expr { 16*1024*1024 }] set ctx [::ggml::create_context $mem_size] puts "ctx: $ctx" set x [::ggml::new_tensor_1d $ctx F32 1] # x is an input variable ::ggml::set_param $ctx $x set a [::ggml::new_tensor_1d $ctx F32 1] set b [::ggml::new_tensor_1d $ctx F32 1] set x2 [::ggml::mul $ctx $x $x] set f [::ggml::add $ctx [::ggml::mul $ctx $a $x2] $b] # build forward computational graph set gf [::ggml::build_forward_expand $ctx $f] puts "gf: $gf" # set the input variable and parameter values ::ggml::set_f32 $x 2.0 ::ggml::set_f32 $a 3.0 ::ggml::set_f32 $b 4.0 # compute set nthreads 10 ::ggml::graph_compute $gf $nthreads # get result puts "f = [::ggml::get_f32_1d $f 0]" # destroy context ::ggml::destroy_context $ctx
See example-opt.tcl
package require ggml proc get_random_tensor_f32 {ctx0 n_dims ne_lst fmin fmax} { ... } # create context set mem_size [expr { 1024*1024*1024 }] set ctx [::ggml::create_context $mem_size] set ne1_lst [list 4 128 1 1] set ne2_lst [list 4 256 1 1] set ne3_lst [list 128 256 1 1] set a [get_random_tensor_f32 $ctx 2 $ne1_lst -1 +1] set b [get_random_tensor_f32 $ctx 2 $ne2_lst -1 +1] ::ggml::set_param $ctx $a ::ggml::set_param $ctx $b set c [get_random_tensor_f32 $ctx 2 $ne3_lst -1 +1] set ab [::ggml::mul_mat $ctx $a $b] set d [::ggml::sub $ctx $c $ab] set e [::ggml::sum $ctx [::ggml::sqr $ctx $d]] set ge [::ggml::new_graph_custom $ctx true] ::ggml::build_forward_expand $ge $e ::ggml::graph_reset $ge ::ggml::graph_compute $ge 1 set fe [::ggml::get_f32_1d $e 0] puts "fe = $fe" set opt_params [::ggml::opt_default_params ADAM] puts "opt_params = $opt_params" ::ggml::opt $ctx $opt_params $e ::ggml::graph_reset $ge ::ggml::graph_compute $ge 1 set fe_opt [::ggml::get_f32_1d $e 0] puts "original e = $fe, optimized e = $fe_opt" ::ggml::destroy_context $ctx