Repository: Project-MONAI/MONAI
File: monai/bundle/scripts.py (Python)

Code before:
        input_shape_,
        converter_kwargs_,
    ) = _pop_args(
        _args,
        "config_file",
        filepath=None,
        ckpt_file=None,
        bundle_root=os.getcwd(),
        net_id=None,
        meta_file=None,
        key_in_ckpt="",
        use_trace=False,
        input_shape=None,
        converter_kwargs={},
    )

    parser = ConfigParser()

    parser.read_config(f=config_file_)
    meta_file_ = (
        os.path.join(bundle_root_, "configs", "metadata.json") if meta_file_ is None else meta_file_
    )
    filepath_ = os.path.join(bundle_root_, "models", "model.ts") if filepath_ is None else filepath_
    ckpt_file_ = os.path.join(bundle_root_, "models", "model.pt") if ckpt_file_ is None else ckpt_file_
    if not os.path.exists(ckpt_file_):
        raise FileNotFoundError(f"ckpt_file in {ckpt_file_} does not exist, please specify it.")
    if os.path.exists(meta_file_):
        parser.read_meta(f=meta_file_)

    net_id_ = "network_def" if net_id_ is None else net_id_
    try:
        parser.get_parsed_content(net_id_)
    except ValueError as e:
        raise ValueError(f"net_id: network_def in {config_file_} does not exist.") from e

    # the rest key-values in the _args are to override config content
    for k, v in _args.items():
        parser[k] = v

    # When export through torch.jit.trace without providing input_shape, will try to parse one from the parser.
    if (not input_shape_) and use_trace:
        input_shape_ = _get_fake_input_shape(parser=parser)

    inputs_: Sequence[Any] | None = [torch.rand(input_shape_)] if input_shape_ else None

    converter_kwargs_.update({"inputs": inputs_, "use_trace": use_trace_})
    # Use the given converter to convert a model and save with metadata, config content
    _export(
        convert_to_torchscript,
        parser,
        net_id=net_id_,

Review comment (suggestion):
```suggestion
        raise FileNotFoundError(f'Checkpoint file "{ckpt_file_}" not found, please specify it in argument "ckpt_file".')
```

Code after:
        input_shape_,
        converter_kwargs_,
    ) = _pop_args(
        _args,
        "config_file",
        filepath=None,
        ckpt_file=None,
        bundle_root=os.getcwd(),
        net_id=None,
        meta_file=None,
        key_in_ckpt="",
        use_trace=False,
        input_shape=None,
        converter_kwargs={},
    )

    parser = ConfigParser()

    parser.read_config(f=config_file_)
    meta_file_ = os.path.join(bundle_root_, "configs", "metadata.json") if meta_file_ is None else meta_file_
    filepath_ = os.path.join(bundle_root_, "models", "model.ts") if filepath_ is None else filepath_
    ckpt_file_ = os.path.join(bundle_root_, "models", "model.pt") if ckpt_file_ is None else ckpt_file_
    if not os.path.exists(ckpt_file_):
        raise FileNotFoundError(f'Checkpoint file "{ckpt_file_}" not found, please specify it in argument "ckpt_file".')
    if os.path.exists(meta_file_):
        parser.read_meta(f=meta_file_)

    net_id_ = "network_def" if net_id_ is None else net_id_
    try:
        parser.get_parsed_content(net_id_)
    except ValueError as e:
        raise ValueError(
            f'Network definition "{net_id_}" cannot be found in "{config_file_}", specify name with argument "net_id".'
        ) from e

    # the rest key-values in the _args are to override config content
    for k, v in _args.items():
        parser[k] = v

    # When export through torch.jit.trace without providing input_shape, will try to parse one from the parser.
    if (not input_shape_) and use_trace:
        input_shape_ = _get_fake_input_shape(parser=parser)

    inputs_: Sequence[Any] | None = [torch.rand(input_shape_)] if input_shape_ else None

    converter_kwargs_.update({"inputs": inputs_, "use_trace": use_trace_})
    # Use the given converter to convert a model and save with metadata, config content
    _export(
        convert_to_torchscript,
        parser,
        net_id=net_id_,