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

[PyTorch] WriteFunction causes SIGSEGV #1244

Closed
HGuillemet opened this issue Oct 11, 2022 · 2 comments
Closed

[PyTorch] WriteFunction causes SIGSEGV #1244

HGuillemet opened this issue Oct 11, 2022 · 2 comments
Labels

Comments

@HGuillemet
Copy link
Collaborator

Trying to serialize tensors or modules to something else than files using OutputArchive.save_to(WriteFunction) causes a segmentation fault.

import org.bytedeco.javacpp.annotation.*;
import org.bytedeco.pytorch.presets.torch.*;
import org.bytedeco.pytorch.*;
import org.bytedeco.javacpp.*;

class T {

  static WriteFunction wf = new WriteFunction() {
      @Override
      @Virtual
      public long call(Pointer buf, long nbytes) {
        System.err.println("writing "+nbytes);
        return nbytes;
      }
    };

  public static void main(String[] a) {
    OutputArchive oa = new OutputArchive();
    Tensor t = AbstractTensor.create(1F, 2F);
    oa.write("test", t);
    oa.save_to(wf);
  }
}

The equivalent following C++ code does work:

#include <torch/torch.h>
#include <iostream>

size_t wf(const void *p, size_t l) {
  std::cerr << "writing " << l << std::endl;
  return l;
}

int main() {
  torch::Tensor t = torch::rand({2, 3});
  torch::serialize::OutputArchive oa;
  oa.write("test", t);
  oa.save_to(wf);
}
@saudet
Copy link
Member

saudet commented Oct 12, 2022

This should be fixed with commit bytedeco/javacpp@f14c30b. Please give it a try!

@HGuillemet
Copy link
Collaborator Author

Works perfectly. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants