ersilia-os / ersilia

The Ersilia Model Hub, a repository of AI/ML models for infectious and neglected disease research.
https://ersilia.io
GNU General Public License v3.0
220 stars 148 forks source link

📑 Feature Request: Run models fetched from DockerHub in Google Colaboratory #789

Open miquelduranfrigola opened 1 year ago

miquelduranfrigola commented 1 year ago

Is your feature request related to a problem? Please describe.

Google Colab does not officially support Docker, which effectively neglects the use of dockerized models in Google Colab notebooks. While Google Colab notebooks have been working just fine with many models using fetching through Conda, we would like to have the option to fetch models directly from Docker Hub.

Describe the solution you'd like.

We want to run Docker in Google Colab. The package udocker seems to offer a solution.

%%shell
pip install udocker
udocker --allow-root install

And then:

%%shell
adduser username 
usermod -aG sudo username

This worked for me:

!sudo -u username udocker pull ersiliaos/eos3b5e

If we accept this solution, we would need to wrap udocker inside Ersilia's docker managers.

Describe alternatives you've considered

Additional context.

No response

miquelduranfrigola commented 1 year ago

In Google Colab, the following works:

%%shell
pip install udocker
udocker --allow-root install
echo "mypwd" | sudo adduser --quiet --disabled-password --gecos "" username
echo "username:mypwd" | sudo chpasswd
miquelduranfrigola commented 1 year ago

This seems to be more difficult than initially expected due to some unanticipated behaviours in Google Colab:

  1. Ports below 1024 are not allowed. This may be solved by: !sudo -u username udocker run -p 8080:80 ersiliaos/eos3b5e:latest bash
  2. For some reason, the localhost inside the container is not found:

    Warning: this container exposes TCP/IP ports
    
    ****************************************************************************** 
    *                                                                            * 
    *               STARTING 035ecdff-1065-3e5c-a78a-e180bac6d5d1                * 
    *                                                                            * 
    ****************************************************************************** 
    executing: sh
    + [ -z eos3b5e ]
    + ersilia serve -p 3000 eos3b5e
    Traceback (most recent call last):
    File "/usr/local/bin/ersilia", line 33, in <module>
    sys.exit(load_entry_point('ersilia', 'console_scripts', 'ersilia')())
    File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
    File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
    File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
    File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
    File "/usr/local/lib/python3.7/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
    File "/root/ersilia/ersilia/cli/commands/__init__.py", line 22, in wrapper
    return func(*args, **kwargs)
    File "/root/ersilia/ersilia/cli/commands/serve.py", line 33, in serve
    mdl.serve()
    File "/root/ersilia/ersilia/core/model.py", line 391, in serve
    self.autoservice.serve()
    File "/root/ersilia/ersilia/serve/autoservice.py", line 345, in serve
    self.service.serve()
    File "/root/ersilia/ersilia/serve/services.py", line 314, in serve
    self._bentoml_serve(self._run_command)
    File "/root/ersilia/ersilia/serve/services.py", line 108, in _bentoml_serve
    self.port = find_free_port(preferred_port=preferred_port)
    File "/root/ersilia/ersilia/utils/ports.py", line 12, in find_free_port
    if not is_port_in_use(preferred_port):
    File "/root/ersilia/ersilia/utils/ports.py", line 7, in is_port_in_use
    return s.connect_ex(("localhost", port)) == 0
    socket.gaierror: [Errno -2] Name or service not known
GemmaTuron commented 1 month ago

Hi,

I think the "Queue" is getting just too large and there is no clear plan or roadmap for when these issues will be tackled. @DhanshreeA what is the current status of running Ersilia in Colab? Is this something we want to maintain? and if yes,what actions are needed?

DhanshreeA commented 1 month ago

Currently, Ersilia is run in Colab using the Python API, which on its own needs to be maintained and has not been tested in some time.

Ideally we should support running dockerized Ersilia models in Colab because of our mission to make Ersilia available as much as possible using free compute resources. As per my initial understanding, this looks like something that can be achieved using a tool called udocker which allows running docker in non privileged settings. And it seems @miquelduranfrigola did some initial work on this regard in Ersilia, however I have not completely verified if this works yet.

Finally, I think it would be a nice to have and we should attempt this one last time before parking it indefinitely.

Update: I was incorrect in saying that Ersilia is run in Colab using the Python API. Ersilia can be run both by using the Python API or the CLI. The Python API is not maintained and possibly runs into issues we are yet not aware of. In addition to that, the test we do have for Ersilia running in Colab notebooks only uses the CLI.

miquelduranfrigola commented 1 month ago

Thanks @DhanshreeA - I tried udocker indeed and I did not succeed. I agree it would be nice to have compatibility with Colab, although it is less urgent of course. How much time do you think we'd need for that?

GemmaTuron commented 1 month ago

@DhanshreeA and @miquelduranfrigola I suggest we leave that issue to one of the Outreachy contributors once they have completed a few initial tasks

DhanshreeA commented 1 month ago

@GemmaTuron, my two cents: this could potentially be quite complicated for an Outreachy contributor, especially if they don't know containers enough. I have not worked with udocker yet either so I would not be able to provide immediate support.