@@ -29,7 +29,7 @@ let%track2_sexp _Pointwise_multiplication_dims_1 (() : unit) : unit =
2929 Rand. init 0 ;
3030 (* "Hey" is inferred to be a scalar. *)
3131 let % op ya = 2 *. " hey" 7.0 in
32- Train. forward_and_forget backend ctx ya;
32+ Train. forward_and_force backend ctx ya;
3333 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Default @@ ya
3434
3535let % track2_sexp _Matrix_multiplication_dims_1x1 (() : unit ) : unit =
@@ -48,11 +48,25 @@ let%track2_sexp _Matrix_multiplication_dims_1x1 (() : unit) : unit =
4848 Rand. init 0 ;
4949 (* Hey is inferred to be a matrix because of matrix multiplication [*]. *)
5050 let % op yb = (" hey" 7.0 * 'q' 2.0 ) + 'p' 1.0 in
51- Train. forward_and_forget backend ctx yb;
51+ Train. forward_and_force backend ctx yb;
5252 (* Punning for ["hey"] above introduced the [hey] identifier. *)
5353 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Default @@ hey;
5454 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Default @@ yb
5555
56+ let % track2_sexp _Print_constant_tensor_too_early (() : unit ) : unit =
57+ Tensor. unsafe_reinitialize () ;
58+ let module Backend = (val Backends. fresh_backend () ) in
59+ let print_tensor = Tensor. print ~with_code: false ~with_grad: false in
60+
61+ let % op a = [| 1. ; 2. ; 3. ; 4. |] in
62+ let % op b = [| 2. ; 3. ; 4. ; 5. |] in
63+ print_tensor ~here: [% here] `Default a;
64+ print_tensor ~here: [% here] `Default b;
65+ let % op c = a *. b in
66+ let ctx = Train. init_params (module Backend ) IDX. empty c in
67+ Train. forward_and_force (module Backend ) ctx c;
68+ print_tensor ~here: [% here] `Default c
69+
5670let % track2_sexp _Print_constant_tensor (() : unit ) : unit =
5771 Tensor. unsafe_reinitialize () ;
5872 let module Backend = (val Backends. fresh_backend () ) in
@@ -68,11 +82,11 @@ let%track2_sexp _Print_constant_tensor (() : unit) : unit =
6882 let ctx = Backend. make_context stream in
6983 Rand. init 0 ;
7084 let % op hey = [ (1 , 2 , 3 ); (4 , 5 , 6 ) ] in
71- Train. forward_and_forget backend ctx hey;
85+ Train. forward_and_force backend ctx hey;
7286 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Inline @@ hey;
7387 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Default @@ hey;
7488 let % op hoo = [| [ 1 ; 2 ; 3 ]; [ 4 ; 5 ; 6 ] |] in
75- Train. forward_and_forget backend ctx hoo;
89+ Train. forward_and_force backend ctx hoo;
7690 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Inline @@ hoo;
7791 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Default @@ hoo;
7892 let % op hey2 =
@@ -83,7 +97,7 @@ let%track2_sexp _Print_constant_tensor (() : unit) : unit =
8397 ((19 , 20 , 21 ), (22 , 23 , 24 ));
8498 ]
8599 in
86- Train. forward_and_forget backend ctx hey2;
100+ Train. forward_and_force backend ctx hey2;
87101 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Inline @@ hey2;
88102 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Default @@ hey2;
89103 let % op hoo2 =
@@ -94,7 +108,7 @@ let%track2_sexp _Print_constant_tensor (() : unit) : unit =
94108 [ [ 19 ; 20 ; 21 ]; [ 22 ; 23 ; 24 ] ];
95109 |]
96110 in
97- Train. forward_and_forget backend ctx hoo2;
111+ Train. forward_and_force backend ctx hoo2;
98112 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Inline @@ hoo2;
99113 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Default @@ hoo2;
100114 let % op heyhoo =
@@ -105,7 +119,7 @@ let%track2_sexp _Print_constant_tensor (() : unit) : unit =
105119 [| [ 19 ; 20 ; 21 ]; [ 22 ; 23 ; 24 ] |];
106120 |]
107121 in
108- Train. forward_and_forget backend ctx heyhoo;
122+ Train. forward_and_force backend ctx heyhoo;
109123 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Inline @@ heyhoo;
110124 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Default @@ heyhoo;
111125 let % op heyhoo2 =
@@ -116,7 +130,7 @@ let%track2_sexp _Print_constant_tensor (() : unit) : unit =
116130 [| [ [ 19 ; 49 ]; [ 20 ; 50 ]; [ 21 ; 51 ] ]; [ [ 22 ; 52 ]; [ 23 ; 53 ]; [ 24 ; 54 ] ] |];
117131 |]
118132 in
119- Train. forward_and_forget backend ctx heyhoo2;
133+ Train. forward_and_force backend ctx heyhoo2;
120134 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Inline @@ heyhoo2;
121135 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Default @@ heyhoo2;
122136 let % op heyhoo3 =
@@ -131,7 +145,7 @@ let%track2_sexp _Print_constant_tensor (() : unit) : unit =
131145 |];
132146 |]
133147 in
134- Train. forward_and_forget backend ctx heyhoo3;
148+ Train. forward_and_force backend ctx heyhoo3;
135149 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Inline @@ heyhoo3;
136150 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Default @@ heyhoo3;
137151 let % op heyhoo4 =
@@ -146,7 +160,7 @@ let%track2_sexp _Print_constant_tensor (() : unit) : unit =
146160 ];
147161 |]
148162 in
149- Train. forward_and_forget backend ctx heyhoo4;
163+ Train. forward_and_force backend ctx heyhoo4;
150164 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Inline @@ heyhoo4;
151165 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Default @@ heyhoo4
152166
@@ -166,7 +180,7 @@ let%track2_sexp _Matrix_multiplication_dims_2x3 (() : unit) : unit =
166180 Rand. init 0 ;
167181 (* Hey is inferred to be a matrix. *)
168182 let % op yc = (" hey" 7.0 * [ 2 ; 3 ]) + [ 4 ; 5 ; 6 ] in
169- Train. forward_and_forget backend ctx yc;
183+ Train. forward_and_force backend ctx yc;
170184 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Default @@ hey;
171185 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Default @@ yc
172186
@@ -188,7 +202,7 @@ let%track2_sexp _Big_matrix (() : unit) : unit =
188202 let hey = TDSL. param ~value: 0.5 " hey" in
189203 let zero_to_twenty = TDSL. range 20 in
190204 let % op yd = (hey * zero_to_twenty) + zero_to_twenty in
191- Train. forward_and_forget backend ctx yd;
205+ Train. forward_and_force backend ctx yd;
192206 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Default hey;
193207 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Default yd
194208
@@ -208,7 +222,7 @@ let%track2_sexp _Very_big_tensor (() : unit) : unit =
208222 Rand. init 0 ;
209223 let hey = TDSL. range_of_shape ~batch_dims: [ 6 ] ~input_dims: [ 7 ; 8 ] ~output_dims: [ 9 ] () in
210224 let % op ye = (hey * (1 + 1 )) - 10 in
211- Train. forward_and_forget backend ctx ye;
225+ Train. forward_and_force backend ctx ye;
212226 Tensor. print ~here: [% here] ~with_code: false ~with_grad: false `Default ye
213227
214228let _suspended (() : unit ) : unit =
@@ -223,7 +237,4 @@ let _suspended (() : unit) : unit =
223237 _Big_matrix () ;
224238 _Very_big_tensor ()
225239
226- let (() : unit) : unit =
227- _Matrix_multiplication_dims_2x3 () ;
228- _Big_matrix () ;
229- _Very_big_tensor ()
240+ let (() : unit) : unit = _Print_constant_tensor_too_early ()
0 commit comments