Missing module 'coremltools.libmilstoragepython'

Hello!

I'm following the Foundation Models adapter training guide (https://developer.apple.com/apple-intelligence/foundation-models-adapter/) on my NVIDIA DGX Spark box. I'm able to train on my own data but the example notebook fails when I try to export the artifact as an fmadapter. I get the following error for the code block I'm trying to run. I haven't touched any of the code in the export folder. I tried exporting it on my Mac too and got the same error as well (given below). Would appreciate some more clarity around this. Thank you.

Code Block:

from export.export_fmadapter import Metadata, export_fmadapter

metadata = Metadata(
    author="3P developer",
    description="An adapter that writes play scripts.",
)

export_fmadapter(
    output_dir="./",
    adapter_name="myPlaywritingAdapter",
    metadata=metadata,
    checkpoint="adapter-final.pt",
    draft_checkpoint="draft-model-final.pt",
)

Error:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[10], line 1
----> 1 from export.export_fmadapter import Metadata, export_fmadapter
      3 metadata = Metadata(
      4     author="3P developer",
      5     description="An adapter that writes play scripts.",
      6 )
      8 export_fmadapter(
      9     output_dir="./",
     10     adapter_name="myPlaywritingAdapter",
   (...)     13     draft_checkpoint="draft-model-final.pt",
     14 )

File /workspace/export/export_fmadapter.py:11
      8 from typing import Any
     10 from .constants import BASE_SIGNATURE, MIL_PATH
---> 11 from .export_utils import AdapterConverter, AdapterSpec, DraftModelConverter, camelize
     13 logger = logging.getLogger(__name__)
     16 class MetadataKeys(enum.StrEnum):

File /workspace/export/export_utils.py:15
     13 import torch
     14 import yaml
---> 15 from coremltools.libmilstoragepython import _BlobStorageWriter as BlobWriter
     16 from coremltools.models.neural_network.quantization_utils import _get_kmeans_lookup_table_and_weight
     17 from coremltools.optimize._utils import LutParams

ModuleNotFoundError: No module named 'coremltools.libmilstoragepython'
Answered by SAIK1065 in 862685022

Figured out the issue, turns out I needed to run this using Python 3.11.12. Version 3.12 and 3.13 would cause this missing module error. In the tutorial it says Python 3.11+ is required but clearly it has to be just some variant of 3.11. Also it only worked on my Mac, not on any other Linux system.

What is the output of pip freeze | grep coremltools, in the Python environment you running this notebook?

Accepted Answer

Figured out the issue, turns out I needed to run this using Python 3.11.12. Version 3.12 and 3.13 would cause this missing module error. In the tutorial it says Python 3.11+ is required but clearly it has to be just some variant of 3.11. Also it only worked on my Mac, not on any other Linux system.

While we investigate whether the new Linux & DGX environment causes this issue of missing dependency, a workaround you can try is to perform the exporting step (saving .fmadapter) on a Mac with the python environment set up as documented. You need to move over the checkpoints (adapter and draft model) from training and call the exporting step there.

great, thx for confirming. We will look into your setup

Missing module 'coremltools.libmilstoragepython'
 
 
Q