<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Error during build process for serving model caused by detectron2 in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/error-during-build-process-for-serving-model-caused-by/m-p/70579#M34097</link>
    <description>&lt;P&gt;Found an answer!&lt;/P&gt;&lt;P&gt;Basically pip was somehow installed the dependencies from the git repo first and was not following the given order so in order to solve this, I added the libraries for conda to install.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;```
conda_env = {
    "channels": [
        "defaults",
        "pytorch"
    ],
    "dependencies": [
        "python=3.8",
        "numpy==1.24.3",
        "pytorch==2.2.2",
        "pip",
        {
            "pip": [
                "fvcore==0.1.5.post20221221",
                "git+https://github.com/wookayin/gpustat",
                "pycocotools==2.0.6",
                "torchvision==0.15.2",
                "git+https://github.com/facebookresearch/detectron2.git"
            ]
        }
    ]
}
```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 24 May 2024 09:54:54 GMT</pubDate>
    <dc:creator>StephenDsouza</dc:creator>
    <dc:date>2024-05-24T09:54:54Z</dc:date>
    <item>
      <title>Error during build process for serving model caused by detectron2</title>
      <link>https://community.databricks.com/t5/data-engineering/error-during-build-process-for-serving-model-caused-by/m-p/70462#M34068</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Introduction&lt;/STRONG&gt;: I am trying to register my model on Databricks so that I can serve it as an endpoint. The packages that I need are&amp;nbsp;&lt;SPAN&gt;"torch"&lt;/SPAN&gt;&lt;SPAN&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"mlflow"&lt;/SPAN&gt;&lt;SPAN&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"torchvision"&lt;/SPAN&gt;&lt;SPAN&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"numpy" and&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"git+&lt;A href="https://github.com/facebookresearch/detectron2.git" target="_blank"&gt;https://github.com/facebookresearch/detectron2.git&lt;/A&gt;". For this, I created a Notebook on Databricks and part of the code is as below:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;class DetectronModel(mlflow.pyfunc.PythonModel):

    def load_context(self, context):
        self.predictor = joblib.load(context.artifacts["predictor"])

    def predict(self, context, model_input):
        image = np.array(model_input["image"])
        result = self.predictor(image)
        instances = result['instances']
        return instances
    

predictor_path = f"/dbfs/mnt/{container_name}/segmentationWeightsPath/predictor.pkl"

conda_env = {
    "channels": ["defaults"],
    "dependencies": [
        "python=3.8",
        "pip",
        {
            "pip": [
                "torch",
                "mlflow",
                "torchvision",
                "numpy",
                "git+https://github.com/facebookresearch/detectron2.git"
            ]
        }
    ]
}

model_info = mlflow.pyfunc.log_model(
    artifact_path="detectron_model_artifact",
    python_model=DetectronModel(),
    artifacts={"predictor": predictor_path},
    conda_env=conda_env
)

model_name = "detectron_model"
model_version = mlflow.register_model(
    model_uri=model_info.model_uri,
    name=model_name
)&lt;/LI-CODE&gt;&lt;P&gt;&lt;STRONG&gt;Problem&lt;/STRONG&gt;: Once the model is registered and I try to serve the model, the build process fails because of a&amp;nbsp;`ModuleNotFoundError: No module named 'torch'` when detectron2 is being installed. Although in the&amp;nbsp;conda_env, torch is clearly added so I am confused why I am getting the error.&lt;BR /&gt;&lt;BR /&gt;I have attached the logs for reference.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;#20 0.390 channels:
#20 0.390 - defaults
#20 0.390 dependencies:
#20 0.390 - python=3.8
#20 0.390 - pip
#20 0.390 - pip:
#20 0.390   - torch
#20 0.390   - mlflow
#20 0.390   - torchvision
#20 0.390   - numpy
#20 0.390   - git+https://github.com/facebookresearch/detectron2.git
#20 0.647 Collecting package metadata (repodata.json): ...working... done
#20 5.820 Solving environment: ...working... done
#20 6.192 
#20 6.192 
#20 6.192 ==&amp;gt; WARNING: A newer version of conda exists. &amp;lt;==
#20 6.192   current version: 4.10.3
#20 6.192   latest version: 24.5.0
#20 6.192 
#20 6.192 Please update conda by running
#20 6.192 
#20 6.192     $ conda update -n base -c defaults conda
#20 6.192 
#20 6.192 
#20 6.202 
#20 6.202 Downloading and Extracting Packages
#20 6.202 
ncurses-6.4          | 914 KB    |            |   0% 
ncurses-6.4          | 914 KB    | ########## | 100% 
ncurses-6.4          | 914 KB    | ########## | 100% 
#20 6.395 
zlib-1.2.13          | 111 KB    |            |   0% 
zlib-1.2.13          | 111 KB    | ########## | 100% 
#20 6.423 
libffi-3.4.4         | 141 KB    |            |   0% 
libffi-3.4.4         | 141 KB    | ########## | 100% 
#20 6.466 
ca-certificates-2024 | 127 KB    |            |   0% 
ca-certificates-2024 | 127 KB    | ########## | 100% 
#20 6.490 
readline-8.2         | 357 KB    |            |   0% 
readline-8.2         | 357 KB    | ########## | 100% 
#20 6.521 
wheel-0.43.0         | 109 KB    |            |   0% 
wheel-0.43.0         | 109 KB    | ########## | 100% 
#20 6.548 
_openmp_mutex-5.1    | 21 KB     |            |   0% 
_openmp_mutex-5.1    | 21 KB     | ########## | 100% 
#20 6.574 
libgomp-11.2.0       | 474 KB    |            |   0% 
libgomp-11.2.0       | 474 KB    | ########## | 100% 
#20 6.608 
ld_impl_linux-64-2.3 | 654 KB    |            |   0% 
ld_impl_linux-64-2.3 | 654 KB    | ########## | 100% 
#20 6.635 
setuptools-69.5.1    | 1002 KB   |            |   0% 
setuptools-69.5.1    | 1002 KB   | ########## | 100% 
#20 6.699 
python-3.8.19        | 23.8 MB   |            |   0% 
python-3.8.19        | 23.8 MB   | ########## | 100% 
python-3.8.19        | 23.8 MB   | ########## | 100% 
#20 7.085 
tk-8.6.14            | 3.4 MB    |            |   0% 
tk-8.6.14            | 3.4 MB    | ########## | 100% 
#20 7.172 
openssl-3.0.13       | 5.2 MB    |            |   0% 
openssl-3.0.13       | 5.2 MB    | ########## | 100% 
#20 7.267 
sqlite-3.45.3        | 1.2 MB    |            |   0% 
sqlite-3.45.3        | 1.2 MB    | ########## | 100% 
#20 7.304 
libgcc-ng-11.2.0     | 5.3 MB    |            |   0% 
libgcc-ng-11.2.0     | 5.3 MB    | ########## | 100% 
libgcc-ng-11.2.0     | 5.3 MB    | ########## | 100% 
#20 7.424 
xz-5.4.6             | 643 KB    |            |   0% 
xz-5.4.6             | 643 KB    | ########## | 100% 
#20 7.463 
libstdcxx-ng-11.2.0  | 4.7 MB    |            |   0% 
libstdcxx-ng-11.2.0  | 4.7 MB    | ########## | 100% 
#20 7.553 
pip-24.0             | 2.6 MB    |            |   0% 
pip-24.0             | 2.6 MB    | ########## | 100% 
pip-24.0             | 2.6 MB    | ########## | 100% 
#20 7.675 Preparing transaction: ...working... done
#20 7.841 Verifying transaction: ...working... done
#20 8.559 Executing transaction: ...working... done
#20 8.934 Installing pip dependencies: ...working... Pip subprocess error:
#20 10.81   Running command git clone --filter=blob:none --quiet https://github.com/facebookresearch/detectron2.git /tmp/pip-req-build-uc1k_xq1
#20 10.81   error: subprocess-exited-with-error
#20 10.81   
#20 10.81   × python setup.py egg_info did not run successfully.
#20 10.81   │ exit code: 1
#20 10.81   ╰─&amp;gt; [6 lines of output]
#20 10.81       Traceback (most recent call last):
#20 10.81         File "&amp;lt;string&amp;gt;", line 2, in &amp;lt;module&amp;gt;
#20 10.81         File "&amp;lt;pip-setuptools-caller&amp;gt;", line 34, in &amp;lt;module&amp;gt;
#20 10.81         File "/tmp/pip-req-build-uc1k_xq1/setup.py", line 10, in &amp;lt;module&amp;gt;
#20 10.81           import torch
#20 10.81       ModuleNotFoundError: No module named 'torch'
#20 10.81       [end of output]
#20 10.81   
#20 10.81   note: This error originates from a subprocess, and is likely not a problem with pip.
#20 10.81 error: metadata-generation-failed
#20 10.81 
#20 10.81 × Encountered error while generating package metadata.
#20 10.81 ╰─&amp;gt; See above for output.
#20 10.81 
#20 10.81 note: This is an issue with the package mentioned above, not pip.
#20 10.81 hint: See above for details.
#20 10.81 
#20 10.81 Ran pip subprocess with arguments:
#20 10.81 ['/opt/conda/envs/mlflow-env/bin/python', '-m', 'pip', 'install', '-U', '-r', '/model/condaenv.detud3st.requirements.txt']
#20 10.81 Pip subprocess output:
#20 10.81 Collecting git+https://github.com/facebookresearch/detectron2.git (from -r /model/condaenv.detud3st.requirements.txt (line 5))
#20 10.81   Cloning https://github.com/facebookresearch/detectron2.git to /tmp/pip-req-build-uc1k_xq1
#20 10.81   Resolved https://github.com/facebookresearch/detectron2.git to commit 79f914785a87b80565381f4489b129e633c4efb5
#20 10.81   Preparing metadata (setup.py): started
#20 10.81   Preparing metadata (setup.py): finished with status 'error'
#20 10.81 
#20 10.81 failed
#20 10.81 
#20 10.81 CondaEnvException: Pip failed
#20 10.81 
#20 ERROR: process "/bin/sh -c echo $BUILD_LOG_START_DELIMITER &amp;amp;&amp;amp; cat model/conda.yaml &amp;amp;&amp;amp; conda env create -f model/conda.yaml -n mlflow-env &amp;amp;&amp;amp; echo $BUILD_LOG_CONDA_END_DELIMITER &amp;amp;&amp;amp; echo $BUILD_LOG_END_DELIMITER &amp;amp;&amp;amp; conda clean -afy" did not complete successfully: exit code: 1
------&lt;/LI-CODE&gt;&lt;P&gt;It looks like the&amp;nbsp;detectron2 is being triggered before torch.&lt;BR /&gt;&lt;BR /&gt;I would like to get some support for my problem and would be happy to share more info.&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2024 11:52:29 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/error-during-build-process-for-serving-model-caused-by/m-p/70462#M34068</guid>
      <dc:creator>StephenDsouza</dc:creator>
      <dc:date>2024-05-23T11:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: Error during build process for serving model caused by detectron2</title>
      <link>https://community.databricks.com/t5/data-engineering/error-during-build-process-for-serving-model-caused-by/m-p/70579#M34097</link>
      <description>&lt;P&gt;Found an answer!&lt;/P&gt;&lt;P&gt;Basically pip was somehow installed the dependencies from the git repo first and was not following the given order so in order to solve this, I added the libraries for conda to install.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;```
conda_env = {
    "channels": [
        "defaults",
        "pytorch"
    ],
    "dependencies": [
        "python=3.8",
        "numpy==1.24.3",
        "pytorch==2.2.2",
        "pip",
        {
            "pip": [
                "fvcore==0.1.5.post20221221",
                "git+https://github.com/wookayin/gpustat",
                "pycocotools==2.0.6",
                "torchvision==0.15.2",
                "git+https://github.com/facebookresearch/detectron2.git"
            ]
        }
    ]
}
```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2024 09:54:54 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/error-during-build-process-for-serving-model-caused-by/m-p/70579#M34097</guid>
      <dc:creator>StephenDsouza</dc:creator>
      <dc:date>2024-05-24T09:54:54Z</dc:date>
    </item>
    <item>
      <title>Re: Error during build process for serving model caused by detectron2</title>
      <link>https://community.databricks.com/t5/data-engineering/error-during-build-process-for-serving-model-caused-by/m-p/139364#M51175</link>
      <description>&lt;P&gt;Hey&lt;/P&gt;&lt;P&gt;How you have added that?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Nov 2025 14:41:01 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/error-during-build-process-for-serving-model-caused-by/m-p/139364#M51175</guid>
      <dc:creator>piotrsofts</dc:creator>
      <dc:date>2025-11-17T14:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: Error during build process for serving model caused by detectron2</title>
      <link>https://community.databricks.com/t5/data-engineering/error-during-build-process-for-serving-model-caused-by/m-p/139478#M51212</link>
      <description>&lt;P&gt;Please ignore my previous message... thanks for hint&lt;/P&gt;</description>
      <pubDate>Tue, 18 Nov 2025 08:25:05 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/error-during-build-process-for-serving-model-caused-by/m-p/139478#M51212</guid>
      <dc:creator>piotrsofts</dc:creator>
      <dc:date>2025-11-18T08:25:05Z</dc:date>
    </item>
  </channel>
</rss>

