@@ -71,7 +71,7 @@ void free_random_uniform_distribution(struct random_uniform_distribution * rnd)
7171
7272struct ggml_tensor * randomize_tensor_normal (struct ggml_tensor * tensor, struct random_normal_distribution * rnd) {
7373 float scale = 1 .0f ; // xavier
74- switch (tensor-> n_dims ) {
74+ switch (ggml_n_dims ( tensor) ) {
7575 case 1 :
7676 scale /= sqrtf ((float ) tensor->ne [0 ]);
7777 for (int i0 = 0 ; i0 < tensor->ne [0 ]; i0++) {
@@ -119,7 +119,7 @@ struct ggml_tensor * randomize_tensor_normal(struct ggml_tensor * tensor, struct
119119}
120120
121121struct ggml_tensor * randomize_tensor_uniform (struct ggml_tensor * tensor, struct random_uniform_distribution * rnd) {
122- switch (tensor-> n_dims ) {
122+ switch (ggml_n_dims ( tensor) ) {
123123 case 1 :
124124 for (int i0 = 0 ; i0 < tensor->ne [0 ]; i0++) {
125125 float * dst = (float *) ((char *) tensor->data + i0*tensor->nb [0 ]);
@@ -183,25 +183,27 @@ float fclamp(const float v, const float min, const float max) {
183183}
184184
185185void assert_shape_1d (struct ggml_tensor * tensor, int64_t ne0) {
186- GGML_ASSERT (tensor->n_dims == 1 );
187186 GGML_ASSERT (tensor->ne [0 ] == ne0);
187+ GGML_ASSERT (tensor->ne [1 ] == 1 );
188+ GGML_ASSERT (tensor->ne [2 ] == 1 );
189+ GGML_ASSERT (tensor->ne [3 ] == 1 );
188190}
189191
190192void assert_shape_2d (struct ggml_tensor * tensor, int64_t ne0, int64_t ne1) {
191- GGML_ASSERT (tensor->n_dims == 2 );
192193 GGML_ASSERT (tensor->ne [0 ] == ne0);
193194 GGML_ASSERT (tensor->ne [1 ] == ne1);
195+ GGML_ASSERT (tensor->ne [2 ] == 1 );
196+ GGML_ASSERT (tensor->ne [3 ] == 1 );
194197}
195198
196199void assert_shape_3d (struct ggml_tensor * tensor, int64_t ne0, int64_t ne1, int64_t ne2) {
197- GGML_ASSERT (tensor->n_dims == 3 );
198200 GGML_ASSERT (tensor->ne [0 ] == ne0);
199201 GGML_ASSERT (tensor->ne [1 ] == ne1);
200202 GGML_ASSERT (tensor->ne [2 ] == ne2);
203+ GGML_ASSERT (tensor->ne [3 ] == 1 );
201204}
202205
203206void assert_shape_4d (struct ggml_tensor * tensor, int64_t ne0, int64_t ne1, int64_t ne2, int64_t ne3) {
204- GGML_ASSERT (tensor->n_dims == 4 );
205207 GGML_ASSERT (tensor->ne [0 ] == ne0);
206208 GGML_ASSERT (tensor->ne [1 ] == ne1);
207209 GGML_ASSERT (tensor->ne [2 ] == ne2);
@@ -225,8 +227,8 @@ int64_t get_example_targets_batch(
225227 bool sample_random_offsets
226228) {
227229 GGML_ASSERT (samples_count > 0 );
228- GGML_ASSERT (tokens_input-> n_dims == 2 );
229- GGML_ASSERT (target_probs-> n_dims == 3 );
230+ GGML_ASSERT (ggml_is_matrix ( tokens_input) );
231+ GGML_ASSERT (ggml_is_3d ( target_probs) );
230232 int64_t n_vocab = target_probs->ne [0 ];
231233 int64_t n_tokens = tokens_input->ne [0 ];
232234 int64_t n_batch = tokens_input->ne [1 ];
0 commit comments