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

How to access the ggml_tensor data? #512

Closed
ebeyabraham opened this issue Sep 8, 2023 · 1 comment
Closed

How to access the ggml_tensor data? #512

ebeyabraham opened this issue Sep 8, 2023 · 1 comment

Comments

@ebeyabraham
Copy link
Contributor

Hi, this may be a silly question but how can I access the data stored in a ggml_tensor? For example, in examples/gpt-2/main.cpp when I try printing some vector as below I get a segmentation fault:

  for (int i = 0; i < 5; ++i) {
      std::cout << ((float*) inpL->data)[i];
  }

The above method used to work for me in a previous version of ggml, but do longer works on the current master.

@ebeyabraham ebeyabraham changed the title How can I access the tensor data? How to access the ggml_tensor data? Sep 8, 2023
@slaren
Copy link
Collaborator

slaren commented Sep 8, 2023

The gpt-2 example was recently updated to use ggml-alloc, and one of the consequences is that tensors don't have data allocated (ie. tensor->data is NULL) until explicitly allocated with ggml_allocr_alloc or ggml_allocr_alloc_graph.

You shouldn't need to access the tensor data unless you are trying to set the inputs (in which case you can use ggml_allocr_alloc to allocate the tensor immediately), or you are trying to retrieve outputs, in which case all the tensors in the graph would have already been allocated by ggml_allocr_alloc_graph. What are you trying to do exactly?

CCLDArjun pushed a commit to CCLDArjun/ggml that referenced this issue Dec 18, 2023
"Processing part 1 of 3" instead of "Processing part 0"
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

No branches or pull requests

2 participants