Skip to content

[PyTorch] WriteFunction causes SIGSEGV #1244

@HGuillemet

Description

@HGuillemet

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions