Running Guild from Python code

Hello, If I want to run guild from some python code with guild.run how i have to set up the project folder and how can i use the configuration file yml

Maybe i can pass as argument to guild.run but is not clear

There are currently a couple interfaces:

I don’t think you want guild.ipy in this case. That’s for running Guild in a Python notebook and for exploring runs with Pandas.

Your best bet for running an operation so that Guild reads the project config is to use Python’s subprocess module.

import subprocess

project_dir = "."  # or whatever

subprocess.call(["guild", "run", "train", "lr=0.1"], cwd=project_dir)

There is an API module guild._api that Guild uses extensively for tests and it’s quite stable. However, it’s not documented and not officially supported.

If you use that I recommend this pattern for import:

from guild import _api as gapi

# Sample run
gapi.run("train", flags={"lr": 0.1}, cwd=project_dir)

At some point this interface may be published but it’s officially unsupported currently. The safest way to interface with Guild, outside of guild.ipy is via subprocess.