Open zyl75391 opened 1 year ago
@zyl75391 Please checkout to dev-3.x branch
生成后会直接退出
如果使用config目录下的config 可以打包但是启动server后会直接退出,使用下载的config 会报错 NameError: name 'false' is not defined 包括false trun 的大小写和 null没有定义
@zyl75391 I'm running into the same issue with rtmdet_ins_l, did you find any workaround?
生成后会直接退出
解决了么?
I'm running into the same AttributeError: 'Namespace' object has no attribute 'config_file'
as OP when trying to create a mar bundle with the mmdet2torchserve.py
script. I tried editing the script so it passes my model config through which allows it to generate a mar bundle. But when I try to run my model in torchserve I'm getting the same java error as @pecanjk and @pecanjk
生成后会直接退出
same here, any solution?
You need to pass in a YAML config file to the model archiver. See https://github.com/pytorch/serve/blob/master/model-archiver/README.md#creating-a-model-archive for more details. They give a sample config file.
You can add this in the mmdet2torchserve.py
file.
The solution is to pass the YAML config file of your model to the torch-model-archiver
in the --extra-files
argument and don't forget to update the _base_
path in the YAML file according to your execution env.
Example:
torch-model-archiver --model-name rtmdetins --version 1.0 --serialized-file best_coco_bbox_mAP_epoch_20.pth --extra-files custom_configs/rtmdet-ins_l_8xb32-300e_coco.py --handler handler.py --export-path model_store/
As a person new to PyTorch & OpenMMLab, I came across this same issue when working with MMRotate and google brought me here when trying to solve the issue.
The important piece is that the call to generate the .mar, within the OpenMMLab script, is broken with newer versions of torch-model-archiver. ( mmdet2torchserve.py
for you and mmrotate2torchserve.py
for me)
At the time of this post, the instantiation of Namespace
is missing an argument, for 'config_file' in mmrotate2torchserve.py
:
args = Namespace(
**{
'model_file': f'{tmpdir}/config.py',
'serialized_file': checkpoint_file,
'handler': f'{Path(__file__).parent}/mmrotate_handler.py',
'model_name': model_name or Path(checkpoint_file).stem,
'version': model_version,
'export_path': output_folder,
'force': force,
'requirements_file': None,
'config_file': None, # <-- This is the line/argument that is missing. If no config yaml is needed, use 'None'
'extra_files': None,
'runtime': 'python',
'archive_format': 'default'
})
manifest = ModelExportUtils.generate_manifest_json(args)
package_model(args, manifest)
Note: The latest
mmdet2torchserve.py
populates 'config_file' with the config python script, which I think is incorrect as it should only be used to populate 'model_file'. It should still fix this error from occurring.
If a config yaml is required, then modify your *2torchserve.py
script to pass in a config yaml value and set that 'config_file' value to it instead of None
.
My biggest blocker with the advice above is the terminology. Models come with two files:
What got me is that when archiving, there is a 3rd, "optional" document: a config yaml. It didn't register that there are two (2) "config files".
The link for an example is above, provided by @roshambo919 but it can be pretty simple:
# TS frontend parameters
# See all supported parameters: https://github.com/pytorch/serve/blob/master/frontend/archive/src/main/java/org/pytorch/serve/archive/model/ModelConfig.java#L14
minWorkers: 1
maxWorkers: 1
Again, it is optional on whether it exists (or not) inside the .mar file.
Another note: If you are new, learning (like me), or going through some of the provided/pre-generated models, using torch-model-archiver
to generate your .mar
file isn't going to work because the *2torchserve.py
"flattens" and renames the configuration script to "config.py":
config = Config.fromfile(config_file)
with TemporaryDirectory() as tmpdir:
config.dump(f'{tmpdir}/config.py')
Thanks for your error report and we appreciate it a lot.
Checklist
Describe the bug A clear and concise description of what the bug is.
Reproduction
What command or script did you run? python tools/deployment/mmdet2torchserve.py rtmdet_tiny_8xb32-300e_coco.py \
line 67, in mmdet2torchserve manifest = ModelExportUtils.generate_manifest_json(args) File "/root/miniconda3/envs/3.10/lib/python3.10/site-packages/model_archiver/model_packaging_utils.py", line 129, in generate_manifest_json model = ModelExportUtils.generate_model(args) File "/root/miniconda3/envs/3.10/lib/python3.10/site-packages/model_archiver/model_packaging_utils.py", line 117, in generate_model config_file=modelargs.config_file, AttributeError: 'Namespace' object has no attribute 'config_file'