serve icon indicating copy to clipboard operation
serve copied to clipboard

handler works when instantiated as an object, but when trying to serve I got this error

Open PMA65 opened this issue 5 years ago • 4 comments

torch-model-archiver --model-name model1
--version 0.0.1
--export-path ./model_store
--handler ./model_handler.py
--serialized-file ./saved_models/weights.pth

first cmd is fine, but when serving torchserve --start
--ncs
--model-store ./model_store
--ts-config ./config.properties

2021-05-21 14:39:37,754 [ERROR] Thread-1 org.pytorch.serve.metrics.MetricCollector - Traceback (most recent call last): File "ts/metrics/metric_collector.py", line 10, in from ts.metrics import system_metrics File "/usr/local/lib/python3.7/dist-packages/ts/init.py", line 10, in from . import version File "/usr/local/lib/python3.7/dist-packages/ts/version.py", line 7, in version_path = os.path.join(Path(file).resolve().parent, 'version.txt') File "/usr/lib/python3.7/posixpath.py", line 80, in join a = os.fspath(a) TypeError: expected str, bytes or os.PathLike object, not PosixPath

PMA65 avatar May 21 '21 14:05 PMA65

Hi @PMA65 this seems like an issue with a specific model that runs on Linux but not Windows

TypeError: expected str, bytes or os.PathLike object, not PosixPath

so if you could share more instructions so I can actually reproduce using the issue template I can help more on my end

msaroufim avatar Jun 20 '21 23:06 msaroufim

Hi @msaroufim I encountered this problem too.

I spent lots of time to investigate the cause. Finally I found that the pathlib package is not correctly installed. Actually there exist two pathlib.py files in the python environment. One is in /path/to/env/lib/python3.x/ and the other is in /path/to/env/lib/python3.x/site-packages/.

The resolution is to remove the file /path/to/env/lib/python3.x/site-packages/pathlib.py, and everything goes well.

Seems like that in the older version of pathlib the PosixPath is not a os.PathLike object, and a sub-thread of TorchServe accidentally loads it rather than the standard pathlib.py.

ckmessi avatar Jul 29 '21 03:07 ckmessi

Currently seeing this on Python3.8 and Python3.9. Regardless of you have the original pathlib.py version, or a site-packages pathlib installed, when the configuration of install_py_dep_per_model is true.

I can confirm that it is importing from the "correct" pathlib.py file in the python3.X root.

marvelous-melanie avatar Aug 10 '21 17:08 marvelous-melanie

so what's the solution to that? It's not causing any issues but it's kinda of a turn off

bely66 avatar May 07 '23 23:05 bely66