Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ggml: add type_size to data view offset calc #777

Closed
wants to merge 1 commit into from

Conversation

danbev
Copy link
Contributor

@danbev danbev commented Mar 31, 2024

This commit suggests adding the type_size to the calculation of the offset when creating a view of a tensor.

The motivation for this change is that when I tried calling ggml_view_1d using an offset like this:

    struct ggml_tensor * view = ggml_view_1d(ctx, x, 5, 0);

Where the x tensor has 10 elments with values ranging from 0 to 9, and requesting a view with 5 elements, starting at offset zero this works as expected.

But if I try using an offset of 5, with the expectation (which may be incorrect) that this would produce a view with the last 5 elements of the tensor x:

    struct ggml_tensor * view = ggml_view_1d(ctx, x, 5, 5);

This does not work as I had expected. This commit contains a test with the above use case, which hopefully clarifies that I'm trying to do and perhaps someone can point out what I'm doing wrong, or confirm that this may be an issue with the current implementation.

This commit suggests adding the type_size to the calculation of the
offset when creating a view of a tensor.

The motivation for this change is that when I tried calling
`ggml_view_1d` using an offset like this:
```c
    struct ggml_tensor * view = ggml_view_1d(ctx, x, 5, 0);
```
Where the `x` tensor has 10 elments with values ranging from 0 to 9,
and requesting a view with 5 elements, starting at offset zero this
works as expected.

But if I try using an offset of 5, with the expectation (which may be
incorrect) that this would produce a view with the last 5 elements of
the tensor `x`:
```c
    struct ggml_tensor * view = ggml_view_1d(ctx, x, 5, 5);
```
This does not work as I had expected. This commit contains a test with
the above use case, which hopefully clarifies that I'm trying to do and
perhaps someone can point out what I'm doing wrong, or confirm that
this may be an issue with the current implementation.

Signed-off-by: Daniel Bevenius <[email protected]>
@slaren
Copy link
Collaborator

slaren commented Mar 31, 2024

The offsets of the views are specified in bytes, and you should do the multiplication yourself in the call to ggml_view_1d. This change is not correct. Check other usages of ggml_view_xd in the examples.

@danbev
Copy link
Contributor Author

danbev commented Apr 1, 2024

The offsets of the views are specified in bytes, and you should do the multiplication yourself in the call to ggml_view_1d

Thanks for clarifying this, it was not clear to me.

@danbev danbev closed this Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants