@@ -71,7 +71,7 @@ void free_random_uniform_distribution(struct random_uniform_distribution * rnd)
71
71
72
72
struct ggml_tensor * randomize_tensor_normal (struct ggml_tensor * tensor, struct random_normal_distribution * rnd) {
73
73
float scale = 1 .0f ; // xavier
74
- switch (tensor-> n_dims ) {
74
+ switch (ggml_n_dims ( tensor) ) {
75
75
case 1 :
76
76
scale /= sqrtf ((float ) tensor->ne [0 ]);
77
77
for (int i0 = 0 ; i0 < tensor->ne [0 ]; i0++) {
@@ -119,7 +119,7 @@ struct ggml_tensor * randomize_tensor_normal(struct ggml_tensor * tensor, struct
119
119
}
120
120
121
121
struct 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) ) {
123
123
case 1 :
124
124
for (int i0 = 0 ; i0 < tensor->ne [0 ]; i0++) {
125
125
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) {
183
183
}
184
184
185
185
void assert_shape_1d (struct ggml_tensor * tensor, int64_t ne0) {
186
- GGML_ASSERT (tensor->n_dims == 1 );
187
186
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 );
188
190
}
189
191
190
192
void assert_shape_2d (struct ggml_tensor * tensor, int64_t ne0, int64_t ne1) {
191
- GGML_ASSERT (tensor->n_dims == 2 );
192
193
GGML_ASSERT (tensor->ne [0 ] == ne0);
193
194
GGML_ASSERT (tensor->ne [1 ] == ne1);
195
+ GGML_ASSERT (tensor->ne [2 ] == 1 );
196
+ GGML_ASSERT (tensor->ne [3 ] == 1 );
194
197
}
195
198
196
199
void assert_shape_3d (struct ggml_tensor * tensor, int64_t ne0, int64_t ne1, int64_t ne2) {
197
- GGML_ASSERT (tensor->n_dims == 3 );
198
200
GGML_ASSERT (tensor->ne [0 ] == ne0);
199
201
GGML_ASSERT (tensor->ne [1 ] == ne1);
200
202
GGML_ASSERT (tensor->ne [2 ] == ne2);
203
+ GGML_ASSERT (tensor->ne [3 ] == 1 );
201
204
}
202
205
203
206
void 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 );
205
207
GGML_ASSERT (tensor->ne [0 ] == ne0);
206
208
GGML_ASSERT (tensor->ne [1 ] == ne1);
207
209
GGML_ASSERT (tensor->ne [2 ] == ne2);
@@ -225,8 +227,8 @@ int64_t get_example_targets_batch(
225
227
bool sample_random_offsets
226
228
) {
227
229
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) );
230
232
int64_t n_vocab = target_probs->ne [0 ];
231
233
int64_t n_tokens = tokens_input->ne [0 ];
232
234
int64_t n_batch = tokens_input->ne [1 ];
0 commit comments