java.lang.NoSuchMethodError when starting Torch Serve
I keep getting this path not found error.
This is from starting the torchserve inside a project:
torchserve --start --model-store model_store --models densenet161=densenet161.mar
% java.lang.NoSuchMethodError: java.nio.file.Files.readString(Ljava/nio/file/Path;)Ljava/lang/String;
at org.pytorch.serve.util.ConfigManager.readFile(ConfigManager.java:196)
at org.pytorch.serve.util.ConfigManager.<init>(ConfigManager.java:108)
at org.pytorch.serve.util.ConfigManager.init(ConfigManager.java:246)
at org.pytorch.serve.ModelServer.main(ModelServer.java:70)
This is from after pulling and building torchserve from git, and running the torchserve_sanity.sh script:
> Task :modelarchive:test
objc[37989]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java (0x10b9184c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10b9924e0). One of the two will be used. Which one is undefined.
ModelArchiverSuite > TorchServe > org.pytorch.serve.archive.CoverageTest > test PASSED
ModelArchiverSuite > TorchServe > org.pytorch.serve.archive.ModelArchiveTest > test PASSED
ModelArchiverSuite > TorchServe > org.pytorch.serve.archive.ModelArchiveTest > testInvalidURL PASSED
ModelArchiverSuite > TorchServe > org.pytorch.serve.archive.ModelArchiveTest > testMalformURL PASSED
> Task :server:compileJava FAILED
/Users/hariharan/Petprojects/torchserve/serve/frontend/server/src/main/java/org/pytorch/serve/util/ConfigManager.java:196: error: cannot find symbol
return Files.readString(Paths.get(path));
^
symbol: method readString(Path)
location: class Files
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':server:compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 11s
18 actionable tasks: 18 executed
Frontend build suite execution failed!!! Check logs for more details
Any ideas or help here please? Also, here's my environment info:
Mac OSX Catalina 10.15.4 (19E287)
% python --version
Python 3.7.4
torch 1.5.1
torch-model-archiver 0.1.1
torchserve 0.1.1
torchtext 0.6.0
torchvision 0.6.1
% java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
You need java 11 for this. Please look at the quick start guide here
Ah sorry. My bad then. I thought Java 8 was the minimum requirement according to this. Let me try with Java 11.
Works now. Sorry for the trouble!
I am getting the same error
(torch_serve1) kanchan.sarkar:~$ java.lang.NoSuchMethodError: java.nio.file.Files.readString(Ljava/nio/file/Path;)Ljava/lang/String; at org.pytorch.serve.util.ConfigManager.readFile(ConfigManager.java:202) at org.pytorch.serve.util.ConfigManager.
(ConfigManager.java:114) at org.pytorch.serve.util.ConfigManager.init(ConfigManager.java:252) at org.pytorch.serve.ModelServer.main(ModelServer.java:70)
when my java version is
openjdk version "11.0.5" 2019-10-15 OpenJDK Runtime Environment (build 11.0.5+10-post-Ubuntu-2ubuntu116.04) OpenJDK 64-Bit Server VM (build 11.0.5+10-post-Ubuntu-2ubuntu116.04, mixed mode, sharing)
please let me know if I am doing anything wrong?
@KanchanIIT: I suspect there are multiple Java versions installed on your machine. Could you please share the output of the following command:
dpkg --list | grep -i jdk
Also share the details about your environment and steps you executed which caused this error.
@SysuCharon: Could you please log a fresh ticket with your environment details per the bug report template?
Facing the same issue on Ubuntu16.04 with PyTorch1.7.1. Related information is listed as follows:
java -version
openjdk version "11.0.5" 2019-10-15 OpenJDK Runtime Environment (build 11.0.5+10-post-Ubuntu-2ubuntu116.04) OpenJDK 64-Bit Server VM (build 11.0.5+10-post-Ubuntu-2ubuntu116.04, mixed mode, sharing)
dpkg --list | grep -i jdk
ii openjdk-11-jdk:amd64 11.0.5+10-2ubuntu1~16.04 amd64 OpenJDK Development Kit (JDK) ii openjdk-11-jdk-headless:amd64 11.0.5+10-2ubuntu1~16.04 amd64 OpenJDK Development Kit (JDK) (headless) ii openjdk-11-jre:amd64 11.0.5+10-2ubuntu1~16.04 amd64 OpenJDK Java runtime, using Hotspot JIT ii openjdk-11-jre-headless:amd64 11.0.5+10-2ubuntu1~16.04 amd64 OpenJDK Java runtime, using Hotspot JIT (headless)
@lucasxlu: Could you please create a fresh ticket with details per the bug report template? Please also share the details of the steps followed
@SysuCharon: Could you please log a fresh ticket with your environment details per the bug report template? @harshbafna thank u I have solved this problem Install JDK first and then torch serve
sudo apt-get install openjdk-11-jdk
This worked for me
seems like it should have installed JAVA like this first if using cuda. Didnt work for me
python ./ts_scripts/install_dependencies.py --cuda=cu102
You need java 11 for this. Please look at the quick start guide here
I recommend adding in torchserve one line of code checking for appropriate java version, and print a good error message.
You need java 11 for this. Please look at the quick start guide here
@dhaniram-kshirsagar this page doesn't mention the term 'java'
This error usually occurs when Java 17 is not installed or used. Java 17 is required by Torchserve and older java versions are not supported. https://pytorch.org/serve/Troubleshooting.html#java-lang-nosuchmethoderror-when-starting-torchserve-473