noop.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. """NoOp builder implementation."""
  2. from __future__ import annotations
  3. from typing import Any
  4. from wandb.sdk.launch.builder.abstract import AbstractBuilder
  5. from wandb.sdk.launch.environment.abstract import AbstractEnvironment
  6. from wandb.sdk.launch.errors import LaunchError
  7. from wandb.sdk.launch.registry.abstract import AbstractRegistry
  8. from .._project_spec import EntryPoint, LaunchProject
  9. from ..agent.job_status_tracker import JobAndRunStatusTracker
  10. class NoOpBuilder(AbstractBuilder):
  11. """NoOp builder."""
  12. type = "noop"
  13. def __init__(
  14. self,
  15. builder_config: dict[str, Any],
  16. environment: AbstractEnvironment,
  17. registry: AbstractRegistry,
  18. ) -> None:
  19. """Initialize a NoOpBuilder."""
  20. self.environment = environment
  21. self.registry = registry
  22. @classmethod
  23. def from_config(
  24. cls,
  25. config: dict,
  26. environment: AbstractEnvironment,
  27. registry: AbstractRegistry,
  28. verify: bool = True,
  29. ) -> AbstractBuilder:
  30. """Create a noop builder from a config."""
  31. return cls(config, environment, registry)
  32. async def verify(self) -> None:
  33. """Verify the builder."""
  34. raise LaunchError("Attempted to verify noop builder.")
  35. async def build_image(
  36. self,
  37. launch_project: LaunchProject,
  38. entrypoint: EntryPoint,
  39. job_tracker: JobAndRunStatusTracker | None = None,
  40. ) -> str:
  41. """Build the image.
  42. For this we raise a launch error since it can't build.
  43. """
  44. raise LaunchError(
  45. "Attempted build with noop builder. Specify a builder in your launch config at ~/.config/wandb/launch-config.yaml.\n"
  46. "Note: Jobs sourced from git repos and code artifacts require a builder, while jobs sourced from Docker images do not.\n"
  47. "See https://docs.wandb.ai/platform/launch/create-job."
  48. )