Пример #1
0
def agent(sweep_id, function=None, entity=None, project=None, count=None):
    """Generic agent entrypoint, used for CLI or jupyter.

    Args:
        sweep_id (dict): Sweep ID generated by CLI or sweep API
        function (func, optional): A function to call instead of the "program" specifed in the config
        entity (str, optional): W&B Entity
        project (str, optional): W&B Project
        count (int, optional): the number of trials to run.
    """
    global _INSTANCES
    _INSTANCES += 1
    try:
        # make sure we are logged in
        wandb_sdk.wandb_login._login(_silent=True)
        if function:
            return pyagent(sweep_id, function, entity, project, count)
        in_jupyter = wandb._get_python_type() != "python"
        return run_agent(
            sweep_id,
            function=function,
            in_jupyter=in_jupyter,
            entity=entity,
            project=project,
            count=count,
        )
    finally:
        _INSTANCES -= 1
Пример #2
0
def agent(sweep_id, function=None, entity=None, project=None, count=None):
    """
    Generic agent entrypoint, used for CLI or jupyter.

    Will run a function or program with configuration parameters specified
    by server.

    Arguments:
        sweep_id: (dict) Sweep ID generated by CLI or sweep API
        function: (func, optional) A function to call instead of the "program"
            specifed in the config.
        entity: (str, optional) W&B Entity
        project: (str, optional) W&B Project
        count: (int, optional) the number of trials to run.

    Examples:
        Run a sample sweep over a function:
        ```
        def train():
            with wandb.init() as run:
                print("config:", dict(run.config))
                for epoch in range(35):
                    print("running", epoch)
                    wandb.log({"metric": run.config.param1, "epoch": epoch})
                    time.sleep(1)

        wandb.agent(sweep_id, function=train)
        ```
    """
    global _INSTANCES
    _INSTANCES += 1
    try:
        # make sure we are logged in
        wandb_sdk.wandb_login._login(_silent=True)
        if function:
            return pyagent(sweep_id, function, entity, project, count)
        in_jupyter = wandb.wandb_sdk.lib.ipython._get_python_type() != "python"
        return run_agent(
            sweep_id,
            function=function,
            in_jupyter=in_jupyter,
            entity=entity,
            project=project,
            count=count,
        )
    finally:
        _INSTANCES -= 1
Пример #3
0
def agent(sweep_id, function=None, entity=None, project=None, count=None):
    """
    Generic agent entrypoint, used for CLI or jupyter.

    Will run a function or program with configuration parameters specified
    by server.

    Arguments:
        sweep_id: (dict) Sweep ID generated by CLI or sweep API
        function: (func, optional) A function to call instead of the "program"
            specifed in the config.
        entity: (str, optional) W&B Entity
        project: (str, optional) W&B Project
        count: (int, optional) the number of trials to run.

    Examples:
        Run a sample sweep over a function:
        <!--yeadoc-test:one-parameter-sweep-agent-->
        ```python
        import wandb
        sweep_configuration = {
            "name": "my-awesome-sweep",
            "metric": {"name": "accuracy", "goal": "maximize"},
            "method": "grid",
            "parameters": {
                "a": {
                    "values": [1, 2, 3, 4]
                }
            }
        }

        def my_train_func():
            # read the current value of parameter "a" from wandb.config
            wandb.init()
            a = wandb.config.a

            wandb.log({"a": a, "accuracy": a + 1})

        sweep_id = wandb.sweep(sweep_configuration)

        # run the sweep
        wandb.agent(sweep_id, function=my_train_func)
        ```
    """
    global _INSTANCES
    _INSTANCES += 1
    try:
        # make sure we are logged in
        wandb_sdk.wandb_login._login(_silent=True)
        if function:
            return pyagent(sweep_id, function, entity, project, count)
        in_jupyter = wandb.wandb_sdk.lib.ipython._get_python_type() != "python"
        return run_agent(
            sweep_id,
            function=function,
            in_jupyter=in_jupyter,
            entity=entity,
            project=project,
            count=count,
        )
    finally:
        _INSTANCES -= 1