Distillation and Finetuning Guide- How to resolve RunTime error from step 7 in Notebook 2 of the guide?

Ufedo Omale 45 Reputation points
2025-08-01T13:19:10.5733333+00:00

Hello.

Question: Please, how do I resolve the run time error I get from running the following code?

Context/Additional Info: How to resolve RunTime error from step 7 (ran on Jupyter Notebook in Azure ML Studio) in Notebook 2 of the Distillation and Finetuning guide. The code comes from this notebook under step 7, Fine-tune with Low-Rank Adaptation (LoRA). The overall goal is distillation and then finetuning. However, my immediate concern is how to resolve the error below.

Thanks!

Code:

! olive finetune \
    --method lora \
    --model_name_or_path  azureml://registries/azureml/models/Phi-4-mini-instruct/versions/1 \
    --trust_remote_code \
    --data_name json \
    --data_files ./data/train_data.jsonl \
    --text_template "<|user|>{Question}<|end|><|assistant|>{Answer}<|end|>" \
    --max_steps 100 \
    --output_path models/phi-4-mini/ft \
    --target_modules "q_proj","k_proj","v_proj","o_proj","gate_proj","up_proj","down_proj" \
    --log_level 1

Error:

Traceback (most recent call last):
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1863, in _get_module
    return importlib.import_module("." + module_name, self.
  File "/anaconda/envs/azureml_py38/lib/python3.10/importlib/
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/transformers/generation/utils.py", line 116, in <module>
    from accelerate.hooks import AlignDevicesHook, add_hook_to_module
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/accelerate/
    from .accelerator import Accelerator
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/accelerate/accelerator.py", line 36, in <module>
    from .checkpointing import load_accelerator_state, load_custom_state, save_accelerator_state, save_custom_state
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/accelerate/checkpointing.py", line 24, in <module>
    from .utils import (
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/accelerate/utils/
    from .bnb import has_4bit_bnb_layers, load_and_quantize_model
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/accelerate/utils/bnb.py", line 29, in <module>
    from ..big_modeling import dispatch_model, init_empty_weights
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/accelerate/big_modeling.py", line 24, in <module>
    from .hooks import (
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/accelerate/hooks.py", line 31, in <module>
    from .utils.other import recursive_getattr
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/accelerate/utils/other.py", line 29, in <module>
    from ..commands.config.default import write_basic_config  # noqa: F401
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/accelerate/commands/config/
    from .config import config_command_parser
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/accelerate/commands/config/config.py", line 25, in <module>
    from .sagemaker import get_sagemaker_input
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/accelerate/commands/config/sagemaker.py", line 35, in <module>
    import boto3  # noqa: F401
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/boto3/
    from boto3.session import Session
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/boto3/session.py", line 17, in <module>
    import botocore.session
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/botocore/session.py", line 29, in <module>
    import botocore.credentials
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/botocore/credentials.py", line 34, in <module>
    from botocore.config import Config
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/botocore/config.py", line 16, in <module>
    from botocore.endpoint import DEFAULT_TIMEOUT, MAX_POOL_CONNECTIONS
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/botocore/endpoint.py", line 22, in <module>
    from botocore.awsrequest import create_request_object
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/botocore/awsrequest.py", line 24, in <module>
    import botocore.utils
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/botocore/utils.py", line 32, in <module>
    import botocore.httpsession
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/botocore/httpsession.py", line 10, in <module>
    from urllib3.util.ssl_ import (
ImportError: cannot import name 'DEFAULT_CIPHERS' from 'urllib3.util.ssl_' (/anaconda/envs/azureml_py38/lib/python3.10/site-packages/urllib3/util/ssl_.py)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1863, in _get_module
    return importlib.import_module("." + module_name, self.
  File "/anaconda/envs/azureml_py38/lib/python3.10/importlib/
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/transformers/models/auto/modeling_auto.py", line 21, in <module>
    from .auto_factory import (
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py", line 40, in <module>
    from ...generation import GenerationMixin
  File "<frozen importlib._bootstrap>", line 1075, in _handle_fromlist
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1851, in 
    module = self._get_module(self._class_to_module[name])
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1865, in _get_module
    raise RuntimeError(
RuntimeError: Failed to import transformers.generation.utils because of the following error (look up to see its traceback):
cannot import name 'DEFAULT_CIPHERS' from 'urllib3.util.ssl_' (/anaconda/envs/azureml_py38/lib/python3.10/site-packages/urllib3/util/ssl_.py)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/anaconda/envs/azureml_py38/bin/olive", line 5, in <module>
    from olive.cli.launcher import main
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/olive/cli/launcher.py", line 9, in <module>
    from olive.cli.auto_opt import AutoOptCommand
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/olive/cli/auto_opt.py", line 27, in <module>
    from olive.package_config import OlivePackageConfig
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/olive/package_config.py", line 12, in <module>
    from olive.passes import PassModuleConfig
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/olive/passes/
    from olive.passes.olive_pass import FullPassConfig, Pass
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/olive/passes/olive_pass.py", line 15, in <module>
    from olive.data.config import DataConfig
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/olive/data/
    from olive.data.component import *  # noqa: F403
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/olive/data/component/
    from olive.data.component import dataloader, load_dataset, post_process_data, pre_process_data
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/olive/data/component/load_dataset.py", line 9, in <module>
    from olive.data.component.dataset import DummyDataset, RawDataset, TransformersDummyDataset
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/olive/data/component/dataset.py", line 13, in <module>
    from olive.common.hf.utils import get_model_config
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/olive/common/hf/utils.py", line 9, in <module>
    from transformers import AutoConfig, AutoModel, AutoTokenizer, GenerationConfig
  File "<frozen importlib._bootstrap>", line 1075, in _handle_fromlist
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1852, in 
    value = getattr(module, name)
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1851, in 
    module = self._get_module(self._class_to_module[name])
  File "/anaconda/envs/azureml_py38/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1865, in _get_module
    raise RuntimeError(
RuntimeError: Failed to import transformers.models.auto.modeling_auto because of the following error (look up to see its traceback):
Failed to import transformers.generation.utils because of the following error (look up to see its traceback):
cannot import name 'DEFAULT_CIPHERS' from 'urllib3.util.ssl_' (/anaconda/envs/azureml_py38/lib/python3.10/site-packages/urllib3/util/ssl_.py)

Azure Machine Learning
0 comments No comments
{count} votes

Accepted answer
  1. Jerald Felix 4,450 Reputation points
    2025-08-05T01:48:27.45+00:00

    Hello Ufedo Omale,

    Thank you for sharing your question about the runtime error you’re encountering in the Distillation and Finetuning guide. It looks like you’re running into an import issue while trying to fine-tune the Phi-4-mini-instruct model with LoRA in an Azure ML Studio Jupyter Notebook, specifically under step 7 of the notebook. The error message points to a problem importing ‘DEFAULT_CIPHERS’ from ‘urllib3.util.ssl_’, which often stems from version incompatibilities between the transformers library and urllib3 in your environment.

    This is a common hiccup in Python environments, especially in managed setups like Azure ML, where pre-installed packages might not align perfectly. Here’s how you can troubleshoot and resolve it step by step:

    1. Check and Update Packages: The root cause is likely an outdated or mismatched version of urllib3 or transformers. In your Jupyter Notebook, try running these commands in a new cell before executing the fine-tuning code: !pip install --upgrade transformers !pip install --upgrade urllib3
    2. After updating, restart the kernel (go to Kernel > Restart) and rerun the cells.
    3. Verify Environment Compatibility: Azure ML’s default environments (like azureml_py38) can sometimes have pinned versions that cause conflicts. If the updates don’t help, consider creating a new compute instance or environment with a more recent Python version (e.g., 3.10 or later) and install the required packages fresh. You can do this in the Azure ML Studio by going to Compute > Create Compute, and then specify a custom environment with your dependencies.
    4. Alternative Workaround: If the error persists, it might be related to how the transformers library is handling SSL configurations. As a quick fix, you could try downgrading urllib3 to a version known to be compatible, such as: !pip install urllib3==1.26.18
    5. But be cautious with downgrades, as they might introduce security issues—test in a non-production setup first.
    6. Test the Command: Once you’ve updated, rerun your olive finetune command. If it still fails, double-check the model path (azureml://registries/azureml/models/Phi-4-mini-instruct/versions/1) and ensure your data file (train_data.jsonl) is correctly formatted and accessible.

    If none of these resolve the issue, it could be specific to your Azure workspace configuration—reaching out to Azure support with the full error traceback would be a good next step, as they can check for any backend limitations.

    I hope this gets you past the error and back on track with your distillation and finetuning workflow!

    Best regards,

    Jerald Felix


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.