fresh-grass-34058
10/13/2023, 12:09 PMpip install git+<https://github.com/openai/CLIP.git>
Works locally. How do I use @pypi decorator to load this model? Anyone know?dry-beach-38304
10/13/2023, 2:34 PMpackages={“clip@git+<https://github.com/openai/CLIP.git”:””>} and that should work (won’t work cross platform yet though can probably do that soon. You can also specify commit/branch/tag the usual way by adding a @ at the end of the url.dry-beach-38304
10/13/2023, 2:34 PMfresh-grass-34058
10/13/2023, 3:05 PMfresh-grass-34058
10/13/2023, 3:05 PMdry-beach-38304
10/13/2023, 3:21 PMdry-beach-38304
10/13/2023, 3:22 PMdry-beach-38304
10/13/2023, 3:22 PMfresh-grass-34058
10/13/2023, 3:22 PMdry-beach-38304
10/13/2023, 3:24 PMdry-beach-38304
10/13/2023, 3:24 PMdry-beach-38304
10/13/2023, 3:25 PMdry-beach-38304
10/13/2023, 3:25 PMfresh-grass-34058
10/13/2023, 3:39 PMdry-beach-38304
10/13/2023, 4:16 PMrequirements.txt file should just contain clip @ git+https:/… and you can pick any version of python you want (it doesn’t matter)
◦ You also don’t need the alias part (basically just call the resolve command)
◦ This does require your batch image to have at least micromamba or mamba on it (mamba is slightly preferred). If it does not have it, you can install it first using the instructions here for example: https://github.com/conda-forge/miniforge#mambaforge (or miniforge, it seems they are the same now). You can just run that (they have a non interactive shell version)
• Once that flow succeeds, it should basically build the wheel for you and cache it. You will then be able to resolve any environment containing that version of clip from your mac (or at least you should, if you can’t or there is any issue, let me know and I’ll take a look).fresh-grass-34058
10/13/2023, 4:23 PMdry-beach-38304
10/13/2023, 4:23 PMfresh-grass-34058
10/13/2023, 4:26 PMdry-beach-38304
10/13/2023, 4:27 PMdry-beach-38304
10/13/2023, 4:28 PMfresh-grass-34058
10/13/2023, 4:31 PMdry-beach-38304
10/13/2023, 4:38 PMdry-beach-38304
10/13/2023, 4:38 PMdry-beach-38304
10/13/2023, 4:43 PMfresh-grass-34058
10/13/2023, 4:57 PMfresh-grass-34058
10/14/2023, 12:21 PMimport subprocess
import sys
import tempfile
from metaflow import FlowSpec, conda, step
class BuildClipWheel(FlowSpec):
@conda(disabled=True)
@step
def start(self):
with tempfile.NamedTemporaryFile(mode="w", encoding="utf-8") as req_file:
req_file.write("clip @ git+<https://github.com/openai/CLIP.git@a1d071733d7111c9c014f024669f959182114e33>")
req_file.flush()
subprocess.check_call(
[
sys.executable,
"-m",
"metaflow.cmd.main_cli",
"environment",
"resolve",
"-r",
req_file.name
]
)
self.next(self.end)
@step
def end(self):
import clip
if __name__ == "__main__":
BuildClipWheel()fresh-grass-34058
10/14/2023, 12:22 PMMetaflow 2.10.2+netflix-ext(1.0.4) executing BuildClipWheel for user:tgallagher
Validating your flow...
The graph looks good!
Running pylint...
Pylint not found, so extra checks are disabled.
Bootstrapping Conda environment... (this could take a few minutes)
Internal error
Traceback (most recent call last):
File "/Users/tgallagher/Library/Python/3.9/lib/python/site-packages/metaflow/cli.py", line 1172, in main
start(auto_envvar_prefix="METAFLOW", obj=state)
File "/Users/tgallagher/Library/Python/3.9/lib/python/site-packages/metaflow/_vendor/click/core.py", line 829, in __call__
return self.main(args, kwargs)
File "/Users/tgallagher/Library/Python/3.9/lib/python/site-packages/metaflow/_vendor/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/Users/tgallagher/Library/Python/3.9/lib/python/site-packages/metaflow/_vendor/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/tgallagher/Library/Python/3.9/lib/python/site-packages/metaflow/_vendor/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, ctx.params)
File "/Users/tgallagher/Library/Python/3.9/lib/python/site-packages/metaflow/_vendor/click/core.py", line 610, in invoke
return callback(args, kwargs)
File "/Users/tgallagher/Library/Python/3.9/lib/python/site-packages/metaflow/cli.py", line 691, in wrapper
return func(args, kwargs)
File "/Users/tgallagher/Library/Python/3.9/lib/python/site-packages/metaflow/_vendor/click/decorators.py", line 33, in new_func
return f(get_current_context().obj, args, kwargs)
File "/Users/tgallagher/Library/Python/3.9/lib/python/site-packages/metaflow/cli.py", line 828, in run
before_run(obj, tags, decospecs + obj.environment.decospecs())
File "/Users/tgallagher/Library/Python/3.9/lib/python/site-packages/metaflow/cli.py", line 886, in before_run
obj.package = MetaflowPackage(
File "/Users/tgallagher/Library/Python/3.9/lib/python/site-packages/metaflow/package.py", line 70, in __init__
environment.init_environment(echo)
File "/Users/tgallagher/Library/Python/3.9/lib/python/site-packages/metaflow_extensions/netflix_ext/plugins/conda/conda_environment.py", line 109, in init_environment
env_type, arch, req, base_env = self.extract_merged_reqs_for_step(
File "/Users/tgallagher/Library/Python/3.9/lib/python/site-packages/metaflow_extensions/netflix_ext/plugins/conda/conda_environment.py", line 579, in extract_merged_reqs_for_step
conda.virtual_packages,
File "/Users/tgallagher/Library/Python/3.9/lib/python/site-packages/metaflow_extensions/netflix_ext/plugins/conda/conda.py", line 225, in virtual_packages
if "virtual_pkgs" in self._info:
File "/Users/tgallagher/Library/Python/3.9/lib/python/site-packages/metaflow_extensions/netflix_ext/plugins/conda/conda.py", line 2172, in _info
self._find_conda_binary()
File "/Users/tgallagher/Library/Python/3.9/lib/python/site-packages/metaflow_extensions/netflix_ext/plugins/conda/conda.py", line 1716, in _find_conda_binary
self._ensure_local_conda()
File "/Users/tgallagher/Library/Python/3.9/lib/python/site-packages/metaflow_extensions/netflix_ext/plugins/conda/conda.py", line 1757, in _ensure_local_conda
err = self._validate_conda_installation()
File "/Users/tgallagher/Library/Python/3.9/lib/python/site-packages/metaflow_extensions/netflix_ext/plugins/conda/conda.py", line 1952, in _validate_conda_installation
if "micromamba version" in self._info_no_lock:
File "/Users/tgallagher/Library/Python/3.9/lib/python/site-packages/metaflow_extensions/netflix_ext/plugins/conda/conda.py", line 2178, in _info_no_lock
self._cached_info = json.loads(self.call_conda(["info", "--json"]))
File "/Users/tgallagher/Library/Python/3.9/lib/python/site-packages/metaflow_extensions/netflix_ext/plugins/conda/conda.py", line 259, in call_conda
if self._bins is None or self._bins[binary] is None:
KeyError: 'conda'dry-beach-38304
10/14/2023, 8:24 PMdry-beach-38304
10/14/2023, 8:43 PMdry-beach-38304
10/14/2023, 10:45 PMmamba (if you didn’t change any of the defaults). There is a bug in the sense that the error message is not clear so I will push a fix for that shortly. The image this runs on needs to have one of conda, mamba or micromamba and you need to configure it as METAFLOW_CONDA_DEPENDENCY_RESOLVER (it defaults to mamba right now). So:
• if your image has mamba , leave the config as is
• if your image has micromamba, set METAFLOW_CONDA_DEPENDENCY_RESOLVER=micromamba
• etc.
The executable needs to be in the path (the code does which to find it.dry-beach-38304
10/14/2023, 10:45 PMend won’t have clip in the env (in your code).dry-beach-38304
10/14/2023, 10:46 PMdry-beach-38304
10/15/2023, 12:07 AMdry-beach-38304
10/15/2023, 12:08 AMdry-beach-38304
10/15/2023, 12:08 AMdry-beach-38304
10/15/2023, 12:09 AMfresh-grass-34058
10/15/2023, 7:02 AMfresh-grass-34058
10/15/2023, 7:03 AMdry-beach-38304
10/15/2023, 7:37 AMdry-beach-38304
10/15/2023, 7:37 AMdry-beach-38304
10/15/2023, 7:37 AMdry-beach-38304
10/15/2023, 7:40 AMdry-beach-38304
10/15/2023, 8:37 AMimport os
import subprocess
import sys
import tempfile
from metaflow import FlowSpec, conda, step
class BuildClipWheel(FlowSpec):
@conda
@step
def start(self):
path = os.environ.get("PATH", "")
home_path = os.environ.get("HOME", "~")
path += ":%s/.local/bin" % home_path
with tempfile.NamedTemporaryFile(mode="w", encoding="utf-8") as req_file:
req_file.write("clip @ git+<https://github.com/openai/CLIP.git@a1d071733d7111c9c014f024669f959182114e33>")
req_file.flush()
subprocess.check_call(
[
sys.executable,
"-m",
"metaflow.cmd.main_cli",
"environment",
"resolve",
"-r",
req_file.name
],
env={**os.environ, "CONDA_CHANNELS": "conda-forge", "PATH": path},
)
self.next(self.end)
@step
def end(self):
print("All done")
if __name__ == "__main__":
BuildClipWheel()
◦ This does use @conda on the resolving step and the reason for that is that you can then take advantage of Metaflow’s auto download of micromamba.
◦ You need to pass it the channels (most likely) because the installed micromamba may not have those channels configured
◦ The path variable makes sure that it can find the installed micromamba (Metaflow here installs it in ~/.local/bin)
• Run using: CONDA_CHANNELS=conda-forge METAFLOW_CONDA_DEPENDENCY_RESOLVER=micromamba python ./flow.py --environment=conda run --with batch
◦ Same reason to pass the channels (if your micromamba properly reports channels not need to do that). You use the micromamba resolver here too so that it can also be used on batch (else Metaflow will look for the default resolver which is mamba)
Once that it done, the package will be built for linux-64 and you can then do stuff like metaflow environment resolve --dry-run -r test.txt --arch linux-64 where test.txt includes the CLIP library and it will work fine (as well as including it in any @pypi decorator.
(caveat: I did find a tiny bug in this process so this will work from 1.0.5 onwards — it will also give a better error message than the one you initially got).dry-beach-38304
10/15/2023, 8:46 AMfresh-grass-34058
10/15/2023, 9:11 AMdry-beach-38304
10/16/2023, 8:37 AM