training_extensions icon indicating copy to clipboard operation
training_extensions copied to clipboard

Training fails when downloading weights - CERTIFICATE_VERIFY_FAILED

Open piotrgrubicki opened this issue 7 months ago • 6 comments

  1. Start the Win app (probably system agnostic)
  2. Create a single label classification project, upload images and annotate them.
  3. Start the EfficientNet-B3 training

EDIT: also observed for MaskRCNN-ResNet50

The training fails. The log reveals problem while downloading weights. The

My suspicion (as I don't know the library code I may be wrong): backbones/torchvision.py, line 100 initializes the model using default torch weights (and not the ones from efficientnet_b3.yaml). It works for EfficientNet-B0 because we are overriding its weights in backbones/efficientnet.py (not nicely hardcoded, we should use the weights from efficientnet_b0.yaml).

Traceback (most recent call last):

  File "jsonargparse\_typehints.py", line 821, in adapt_typehints
    vals.append(adapt_typehints(val, subtypehint, **adapt_kwargs))
    │    │      │               │    │              └ {'serialize': False, 'instantiate_classes': True, 'prev_val': None, 'append': False, 'enable_path': False, 'sub_add_kwargs': ...
    │    │      │               │    └ <class 'NoneType'>
    │    │      │               └ {'class_path': 'getitune.backend.lightning.models.classification.multiclass_models.TVModelMulticlassCls', 'init_args': {'labe...
    │    │      └ <function adapt_typehints at 0x000001FC0D9DC680>
    │    └ <method 'append' of 'list' objects>
    └ [URLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer...

  File "jsonargparse\_typehints.py", line 1073, in adapt_typehints
    val = adapt_class_type(val, serialize, instantiate_classes, sub_add_kwargs, prev_val=prev_val)
          │                │    │          │                    │                        └ Namespace(class_path='getitune.backend.lightning.models.base.LightningModel')
          │                │    │          │                    └ {'fail_untyped': False, 'sub_configs': True, 'instantiate': True}
          │                │    │          └ True
          │                │    └ False
          │                └ Namespace(class_path='getitune.backend.lightning.models.classification.multiclass_models.TVModelMulticlassCls', init_args=Nam...
          └ <function adapt_class_type at 0x000001FC0D9DD260>

  File "jsonargparse\_typehints.py", line 1392, in adapt_class_type
    return instantiator_fn(val_class, **{**init_args, **dict_kwargs})
           │               │               │            └ {}
           │               │               └ Namespace(label_info=['plush toy', 'vehicle'], data_input_params=DataInputParams(input_size=(224, 224), mean=(0.0, 0.0, 0.0),...
           │               └ <class 'getitune.backend.lightning.models.classification.multiclass_models.torchvision_model.TVModelMulticlassCls'>
           └ <function default_class_instantiator at 0x000001FC0D93CE00>

  File "jsonargparse\_common.py", line 155, in default_class_instantiator
    return class_type(*args, **kwargs)
           │           │       └ {'label_info': ['plush toy', 'vehicle'], 'data_input_params': DataInputParams(input_size=(224, 224), mean=(0.0, 0.0, 0.0), st...
           │           └ ()
           └ <class 'getitune.backend.lightning.models.classification.multiclass_models.torchvision_model.TVModelMulticlassCls'>

  File "getitune\backend\lightning\models\classification\multiclass_models\torchvision_model.py", line 60, in __init__
    super().__init__(

  File "getitune\backend\lightning\models\classification\multiclass_models\base.py", line 66, in __init__
    super().__init__(

  File "getitune\backend\lightning\models\base.py", line 187, in __init__
    self.model = self._create_model()
    │            │    └ <function TVModelMulticlassCls._create_model at 0x000001FC0FC91B20>
    │            └ TVModelMulticlassCls()
    └ TVModelMulticlassCls()

  File "getitune\backend\lightning\models\classification\multiclass_models\torchvision_model.py", line 73, in _create_model
    backbone = TorchvisionBackbone(backbone=self.model_name)
               │                            │    └ 'efficientnet_b3'
               │                            └ TVModelMulticlassCls()
               └ <class 'getitune.backend.lightning.models.classification.backbones.torchvision.TorchvisionBackbone'>

  File "getitune\backend\lightning\models\classification\backbones\torchvision.py", line 100, in __init__
    net = get_model(**tv_model_cfg)
          │           └ {'name': 'efficientnet_b3', 'weights': <enum 'EfficientNet_B3_Weights'>}
          └ <function get_model at 0x000001FBCB1A7EC0>

  File "torchvision\models\_api.py", line 277, in get_model
    return fn(**config)
           │    └ {'weights': <enum 'EfficientNet_B3_Weights'>}
           └ <function efficientnet_b3 at 0x000001FBCEC334C0>

  File "torchvision\models\_utils.py", line 142, in wrapper
    return fn(*args, **kwargs)
           │   │       └ {'weights': <enum 'EfficientNet_B3_Weights'>}
           │   └ ()
           └ <function efficientnet_b3 at 0x000001FBCEC33560>

  File "torchvision\models\_utils.py", line 228, in inner_wrapper
    return builder(*args, **kwargs)
           │        │       └ {'weights': EfficientNet_B3_Weights.IMAGENET1K_V1}
           │        └ ()
           └ <function efficientnet_b3 at 0x000001FBCEC337E0>

  File "torchvision\models\efficientnet.py", line 864, in efficientnet_b3
    return _efficientnet(
           └ <function _efficientnet at 0x000001FBCEC49E40>

  File "torchvision\models\efficientnet.py", line 361, in _efficientnet
    model.load_state_dict(weights.get_state_dict(progress=progress, check_hash=True))
    │     │               │       │                       └ True
    │     │               │       └ <function WeightsEnum.get_state_dict at 0x000001FBCB1A7600>
    │     │               └ EfficientNet_B3_Weights.IMAGENET1K_V1
    │     └ <function Module.load_state_dict at 0x000001FBC4D26CA0>
    └ EfficientNet(
        (features): Sequential(
          (0): Conv2dNormActivation(
            (0): Conv2d(3, 40, kernel_size=(3, 3), stride=(2...

  File "torchvision\models\_api.py", line 91, in get_state_dict
    return load_state_dict_from_url(self.url, *args, **kwargs)
           │                        │    │     │       └ {'progress': True, 'check_hash': True}
           │                        │    │     └ ()
           │                        │    └ <property object at 0x000001FBCB1B30B0>
           │                        └ EfficientNet_B3_Weights.IMAGENET1K_V1
           └ <function load_state_dict_from_url at 0x000001FBC649A7A0>

  File "torch\hub.py", line 880, in load_state_dict_from_url
    download_url_to_file(url, cached_file, hash_prefix, progress=progress)
    │                    │    │            │                     └ True
    │                    │    │            └ 'b3899882'
    │                    │    └ 'C:\\Users\\sys_k8sworker/.cache\\torch\\hub\\checkpoints\\efficientnet_b3_rwightman-b3899882.pth'
    │                    └ 'https://download.pytorch.org/models/efficientnet_b3_rwightman-b3899882.pth'
    └ <function download_url_to_file at 0x000001FBC649A520>

  File "torch\hub.py", line 736, in download_url_to_file
    with urlopen(req) as u:
         │       └ <urllib.request.Request object at 0x000001FC14420E10>
         └ <function urlopen at 0x000001FB7EFFD9E0>

  File "urllib\request.py", line 189, in urlopen

  File "urllib\request.py", line 489, in open

  File "urllib\request.py", line 506, in _open

  File "urllib\request.py", line 466, in _call_chain

  File "urllib\request.py", line 1367, in https_open

  File "urllib\request.py", line 1322, in do_open

urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1032)>

piotrgrubicki avatar Apr 23 '26 10:04 piotrgrubicki

@piotrgrubicki can you check if it's still reproducible on latest develop? I can train EfficientNet-B3 models without any problem to download the weights.

leoll2 avatar Apr 28 '26 15:04 leoll2

@leoll2 , I quickly checked on the latest develop on Ubuntu. It still downloads the weights from the wrong location: First:

2026-04-29 07:55:41.034 | WARNING  | app.services.base_weights_service:_check_disk_space:177 - Could not check remote file size for https://storage.geti.intel.com/weights/efficientnet_b3_rwightman-b3899882.pth: HTTPSConnectionPool(host='storage.geti.intel.com', port=443): Read timed out. (read timeout=10), assuming 500MB
2026-04-29 07:55:42.308 | INFO     | app.services.base_weights_service:_download_weights:221 - Successfully downloaded and verified weights: /application/data/pretrained_weights/classification/efficientnet_b3_rwightman-b3899882.pth

and then:

2026-04-29 07:55:42.663 | INFO     | app.execution.training.getitune_trainer:train_model:382 - Instantiating the LightningModel for training (model_id=44ab3752-db31-4cbe-a6fb-2aa7cb90c0ad)
UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing `weights=EfficientNet_B3_Weights.IMAGENET1K_V1`. You can also use `weights=EfficientNet_B3_Weights.DEFAULT` to get the most up-to-date weights.
Downloading: "https://download.pytorch.org/models/efficientnet_b3_rwightman-b3899882.pth" to /home/non-root/.cache/torch/hub/checkpoints/efficientnet_b3_rwightman-b3899882.pth
100%|██████████| 47.2M/47.2M [00:00<00:00, 111MB/s]

I am running the Win build to confirm the problem is still there.

piotrgrubicki avatar Apr 29 '26 08:04 piotrgrubicki

@leoll2 , the problem is still there. As can be seen in my previous comment, the weights are downloaded from two locations. See my original post where I indicated a suspicious piece of code. On Win, on an instance located in the lab, the 2nd download fails as described originally. It works on Win on my corporate laptop.

piotrgrubicki avatar Apr 29 '26 08:04 piotrgrubicki

@leoll2 This issue is part of a larger problem already captured here. A proper fix requires evaluating all supported model implementations, and I don't think we can deliver it before the release.

The Copilot PR which currently addresses weight path injection for getitune.backend.lightning.models.classification.multiclass_models.torchvision_model.TVModelMulticlassCls (which is the base for efficientnet_b3 according to recipe) in theory can serve as a starting point.

itallix avatar May 07 '26 09:05 itallix

Thanks for the analysis, Vitalii. The problem is indeed not easy to solve and it requires a large restructuring of the weight provisioning mechanisms in the library, that's already in scope of #5100. I reviewed the Copilot PR and while it contains good ideas for the aforementioned refactoring, I wouldn't merge it for 3.0 because it looks hacky and risky, and probably won't solve the issue for all models. Considering that the bug doesn't affect all deployments (I verified that EfficientNet-B3 weights can be downloaded in my local env), I will reduce the exposure to Medium and postpone the solution to 3.1.

leoll2 avatar May 07 '26 10:05 leoll2

Proper provisioning mechanism is introduced in #6982. Models are loaded with weights specified in app manifests now.

itallix avatar Jul 20 '26 12:07 itallix