Skip to content

Commit

Permalink
Avoid importing launchpad if not actually used (by non-distributed ag…
Browse files Browse the repository at this point in the history
…ents).

PiperOrigin-RevId: 415226384
Change-Id: I24f2ca520a7e3e179949adfc974274bf082a458c
  • Loading branch information
qstanczyk authored and copybara-github committed Dec 9, 2021
1 parent 60d51d3 commit b7cbdf5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions acme/utils/lp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
import os
import sys
import time
from typing import Any, Callable, Optional
from typing import Any, Callable

from absl import flags
from absl import logging
from acme.utils import counting
import launchpad as lp

FLAGS = flags.FLAGS

Expand Down Expand Up @@ -97,6 +96,8 @@ def run(self):
if num_steps > self._max_steps:
logging.info('StepsLimiter: Max steps of %d was reached, terminating',
self._max_steps)
# Avoid importing Launchpad until it is actually used.
import launchpad as lp # pylint: disable=g-import-not-at-top
lp.stop()

# Don't spam the counter.
Expand All @@ -107,8 +108,7 @@ def run(self):


# Resources for each individual instance of the program.
def make_xm_docker_resources(program: lp.Program,
requirements: Optional[str] = None):
def make_xm_docker_resources(program, requirements):
"""Returns Docker XManager resources for each program's node.
For each node of the Launchpad's program appropriate hardware requirements are
Expand All @@ -125,6 +125,8 @@ def make_xm_docker_resources(program: lp.Program,
# Avoid importing 'xmanager' for local runs.
return None

# Avoid importing Launchpad until it is actually used.
import launchpad as lp # pylint: disable=g-import-not-at-top
# Reference lp.DockerConfig to force lazy import of xmanager by Launchpad and
# then import it. It is done this way to avoid heavy imports by default.
lp.DockerConfig # pylint: disable=pointless-statement
Expand Down

0 comments on commit b7cbdf5

Please sign in to comment.