[pytorch] 2.1.2-1.5.10 release run example meet error [ Pointer address of argument 0 is NULL.]
mullerhai opened this issue · 5 comments
Hi, feeling exciting to use javacpp [pytorch] 2.1.2-1.5.10 ,but when I running our example meet error ,I don't know why ,but the dataset real path is exist ,why the program can not read them?
Macos latest
java 1.8 && scala 2.11.11 all try
import org.bytedeco.javacpp._
import org.bytedeco.pytorch._
import org.bytedeco.pytorch.Module
import org.bytedeco.pytorch.global.torch._
object SimpleMNIST { // Define a new Module.
class Net() extends Module { // Construct and register two Linear submodules.
final var fc1: LinearImpl = register_module("fc1", new LinearImpl(784, 64))
final var fc2: LinearImpl = register_module("fc2", new LinearImpl(64, 32))
final var fc3: LinearImpl= register_module("fc3", new LinearImpl(32, 10))
// Implement the Net's algorithm.
def forward(xs: Tensor): Tensor = { // Use one of many tensor manipulation functions.
var x = xs
x = relu(fc1.forward(x.reshape(x.size(0), 784)))
x = dropout(x, /*p=*/ 0.5, /*train=*/ is_training)
x = relu(fc2.forward(x))
x = log_softmax(fc3.forward(x), /*dim=*/ 1)
x
}
}
@throws[Exception]
def main(args: Array[String]): Unit = {
/* try to use MKL when available */
System.setProperty("org.bytedeco.openblas.load", "mkl")
// Create a new Net.
val net = new SimpleMNIST.Net
// Create a multi-threaded data loader for the MNIST dataset.
val path = "/Users/zhanghaining/Downloads/mnist/" //"./data"
// val pathz = "/Users/zhanghaining/Documents/codeWorld/untitled/data/"
val pathz = "/Users/zhanghaining/Downloads/pytorchScala/data/"
val paths = "/Users/zhanghaining/Downloads/pytorchScala/data/"
val mnist = new MNIST(paths)
val data_set = mnist.map(new ExampleStack)
val data_loader = new MNISTRandomDataLoader(data_set, new RandomSampler(data_set.size.get), new DataLoaderOptions(/*batch_size=*/ 64))
// Instantiate an SGD optimization algorithm to update our Net's parameters.
val optimizer = new SGD(net.parameters, new SGDOptions(/*lr=*/ 0.01))
for (epoch <- 1 to 10) {
var batch_index = 0
// Iterate the data loader to yield batches from the dataset.
var it = data_loader.begin
while ( {
!(it == data_loader.end)
}) {
val batch = it.access
// Reset gradients.
optimizer.zero_grad()
// Execute the model on the input data.
val prediction = net.forward(batch.data)
// Compute a loss value to judge the prediction of our model.
val loss = nll_loss(prediction, batch.target)
// Compute gradients of the loss w.r.t. the parameters of our model.
loss.backward()
// Update the parameters based on the calculated gradients.
optimizer.step
// Output the loss and checkpoint every 100 batches.
if ( {
batch_index += 1; batch_index
} % 100 == 0) {
System.out.println("Epoch: " + epoch + " | Batch: " + batch_index + " | Loss: " + loss.item_float)
// Serialize your model periodically as a checkpoint.
val archive = new OutputArchive
net.save(archive)
archive.save_to("net.pt")
}
it = it.increment
}
}
}
}
Exception in thread "main" java.lang.NullPointerException: Pointer address of argument 0 is NULL.
at org.bytedeco.pytorch.MNISTBatchDataset.map(Native Method)
at SimpleMNIST$.main(example.scala:39)
at SimpleMNIST.main(example.scala)
when I running the chunkdataset also meet this error
/* try to use MKL when available */
System.setProperty("org.bytedeco.openblas.load", "mkl")
// Create a new Net.
import org.bytedeco.pytorch.ChunkDataReader
import org.bytedeco.pytorch.ChunkDataset
import org.bytedeco.pytorch.ChunkDatasetOptions
import org.bytedeco.pytorch.ChunkMapDataset
import org.bytedeco.pytorch.ChunkRandomDataLoader
import org.bytedeco.pytorch.ChunkSharedBatchDataset
import org.bytedeco.pytorch.DataLoaderOptions
import org.bytedeco.pytorch.Example
import org.bytedeco.pytorch.ExampleIterator
import org.bytedeco.pytorch.ExampleStack
import org.bytedeco.pytorch.ExampleVector
import org.bytedeco.pytorch.RandomSampler
import org.bytedeco.pytorch.Tensor
val batch_size = 10
val prefetch_count = 1
val data_reader = new ChunkDataReader() {
override def read_chunk(chunk_index: Long) = new ExampleVector(new Example(torch.ones(1), torch.ones(1)), new Example(torch.ones(1), torch.ones(1)))
override def chunk_count = 1
override def reset(): Unit = {
}
}
val sampler = new RandomSampler(0)
val data_set = new ChunkSharedBatchDataset(new ChunkDataset(data_reader, sampler, sampler, new ChunkDatasetOptions(prefetch_count, batch_size))).map(new ExampleStack)
val data_loaders: ChunkRandomDataLoaderBase = new ChunkRandomDataLoader(data_set, new DataLoaderOptions(batch_size))
for (epoch <- 1 to 10) {
var it = data_loaders.begin()
while ( {
!(it == data_loaders.end)
}) {
val batch = it.access
println(s" ${batch.data.createIndexer } ${batch.target.createIndexer} " )
it = it.increment
}
}
error
/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/bin/java -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=58358:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/lib/rt.jar:/Users/zhanghaining/Downloads/pytorchScala/target/scala-2.12/classes:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/javacpp-platform/1.5.11-SNAPSHOT/javacpp-platform-1.5.11-20240211.152631-54.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/javacpp/1.5.11-SNAPSHOT/javacpp-1.5.11-20240211.152855-41-android-arm64.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/javacpp/1.5.11-SNAPSHOT/javacpp-1.5.11-20240211.152855-41-android-x86_64.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/javacpp/1.5.11-SNAPSHOT/javacpp-1.5.11-20240211.152855-41-ios-arm64.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/javacpp/1.5.11-SNAPSHOT/javacpp-1.5.11-20240211.152855-41-ios-x86_64.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/javacpp/1.5.11-SNAPSHOT/javacpp-1.5.11-20240211.152855-41.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/javacpp/1.5.11-SNAPSHOT/javacpp-1.5.11-20240211.152855-41-linux-arm64.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/javacpp/1.5.11-SNAPSHOT/javacpp-1.5.11-20240211.152855-41-linux-ppc64le.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/javacpp/1.5.11-SNAPSHOT/javacpp-1.5.11-20240211.152855-41-linux-x86_64.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/javacpp/1.5.11-SNAPSHOT/javacpp-1.5.11-20240211.152855-41-macosx-arm64.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/javacpp/1.5.11-SNAPSHOT/javacpp-1.5.11-20240211.152855-41-macosx-x86_64.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/javacpp/1.5.11-SNAPSHOT/javacpp-1.5.11-20240211.152855-41-windows-x86_64.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/openblas-platform/0.3.26-1.5.11-SNAPSHOT/openblas-platform-0.3.26-1.5.11-20240130.093148-17.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/openblas/0.3.26-1.5.11-SNAPSHOT/openblas-0.3.26-1.5.11-20240129.142557-11-android-arm64.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/openblas/0.3.26-1.5.11-SNAPSHOT/openblas-0.3.26-1.5.11-20240129.142557-11-android-x86_64.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/openblas/0.3.26-1.5.11-SNAPSHOT/openblas-0.3.26-1.5.11-20240129.142557-11-ios-arm64.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/openblas/0.3.26-1.5.11-SNAPSHOT/openblas-0.3.26-1.5.11-20240129.142557-11-ios-x86_64.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/openblas/0.3.26-1.5.11-SNAPSHOT/openblas-0.3.26-1.5.11-20240129.142557-11.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/openblas/0.3.26-1.5.11-SNAPSHOT/openblas-0.3.26-1.5.11-20240129.142557-11-linux-arm64.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/openblas/0.3.26-1.5.11-SNAPSHOT/openblas-0.3.26-1.5.11-20240129.142557-11-linux-ppc64le.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/openblas/0.3.26-1.5.11-SNAPSHOT/openblas-0.3.26-1.5.11-20240129.142557-11-linux-x86_64.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/openblas/0.3.26-1.5.11-SNAPSHOT/openblas-0.3.26-1.5.11-20240129.142557-11-macosx-arm64.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/openblas/0.3.26-1.5.11-SNAPSHOT/openblas-0.3.26-1.5.11-20240129.142557-11-macosx-x86_64.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/openblas/0.3.26-1.5.11-SNAPSHOT/openblas-0.3.26-1.5.11-20240129.142557-11-windows-x86_64.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/pytorch-platform/2.1.2-1.5.11-SNAPSHOT/pytorch-platform-2.1.2-1.5.11-20240130.011732-4.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/pytorch/2.1.2-1.5.11-SNAPSHOT/pytorch-2.1.2-1.5.11-20240130.093152-7.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/pytorch/2.1.2-1.5.11-SNAPSHOT/pytorch-2.1.2-1.5.11-20240130.093152-7-linux-x86_64.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/pytorch/2.1.2-1.5.11-SNAPSHOT/pytorch-2.1.2-1.5.11-20240130.093152-7-macosx-x86_64.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/oss.sonatype.org/content/repositories/snapshots/org/bytedeco/pytorch/2.1.2-1.5.11-SNAPSHOT/pytorch-2.1.2-1.5.11-20240130.093152-7-windows-x86_64.jar:/Users/zhanghaining/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.12.11/scala-library-2.12.11.jar SimpleMNIST
Exception in thread "main" java.lang.NullPointerException: Pointer address of argument 0 is NULL.
at org.bytedeco.pytorch.ChunkBatchSharedBatchDataset.map(Native Method)
at SimpleMNIST$.main(example.scala:57)
at SimpleMNIST.main(example.scala)
The ExampleStack
and TensorExampleStack
classes have lost their native constructors in 2.1.2-1.5.10.
They are back in PR #1466.
Can you work around that in the meantime, for your needs ?
Maybe using the new DataLoader classes ?
The
ExampleStack
andTensorExampleStack
classes have lost their native constructors in 2.1.2-1.5.10. They are back in PR #1466. Can you work around that in the meantime, for your needs ? Maybe using the new DataLoader classes ?
oh,rollback the code,then could we update 2.1.2-1.5.10 Maven public repo with our has test and correct code ?thanks
Maybe can we release a 2.2.0-1.5.10 version based on PR 1466. What do you think @saudet ?