beta.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. """Beta versions of wandb CLI commands.
  2. These commands are experimental and may change or be removed in future versions.
  3. """
  4. from __future__ import annotations
  5. import pathlib
  6. import click
  7. from wandb.analytics import get_sentry
  8. from wandb.errors import WandbCoreNotAvailableError
  9. from wandb.util import get_core_path
  10. @click.group()
  11. def beta():
  12. """Beta versions of wandb CLI commands.
  13. These commands may change or even completely break in any release of wandb.
  14. """
  15. get_sentry().configure_scope(process_context="wandb_beta")
  16. try:
  17. get_core_path()
  18. except WandbCoreNotAvailableError as e:
  19. get_sentry().exception(f"using `wandb beta`. failed with {e}")
  20. click.secho(
  21. (e),
  22. fg="red",
  23. err=True,
  24. )
  25. @beta.command()
  26. @click.argument("path", nargs=1, type=click.Path(exists=True), required=False)
  27. def leet(path: str | None = None) -> None:
  28. """Launch W&B LEET: the Lightweight Experiment Exploration Tool.
  29. LEET is a terminal UI for viewing a W&B run specified by an optional PATH.
  30. PATH can include a .wandb file or a run directory containing a .wandb file.
  31. If PATH is not provided, the command will look for the latest run.
  32. """
  33. from . import beta_leet
  34. beta_leet.launch(path)
  35. @beta.command()
  36. @click.argument("paths", type=click.Path(exists=True), nargs=-1)
  37. @click.option(
  38. "--live",
  39. is_flag=True,
  40. default=False,
  41. help="""Sync a run while it's still being logged.
  42. This may hang if the process generating the run crashes uncleanly.
  43. """,
  44. )
  45. @click.option(
  46. "-e",
  47. "--entity",
  48. default="",
  49. help="An entity override to use for all runs being synced.",
  50. )
  51. @click.option(
  52. "-p",
  53. "--project",
  54. default="",
  55. help="A project override to use for all runs being synced.",
  56. )
  57. @click.option(
  58. "--id",
  59. "run_id",
  60. default="",
  61. help="""A run ID override to use for all runs being synced.
  62. If setting this and syncing multiple files (with the same entity
  63. and project), the files will be synced in order of start time.
  64. This is intended to work with syncing multiple resumed fragments
  65. of the same run.
  66. """,
  67. )
  68. @click.option(
  69. "--skip-synced/--no-skip-synced",
  70. is_flag=True,
  71. default=True,
  72. help="Skip runs that have already been synced with this command.",
  73. )
  74. @click.option(
  75. "--dry-run",
  76. is_flag=True,
  77. default=False,
  78. help="Print what would happen without uploading anything.",
  79. )
  80. @click.option(
  81. "-v",
  82. "--verbose",
  83. is_flag=True,
  84. default=False,
  85. help="Print more information.",
  86. )
  87. @click.option(
  88. "-n",
  89. default=5,
  90. help="""Max number of runs to sync at a time.
  91. When syncing multiple files that are part of the same run,
  92. the files are synced sequentially in order of start time
  93. regardless of this setting. This happens for resumed runs
  94. or when using the --id parameter.
  95. """,
  96. )
  97. def sync(
  98. paths: tuple[str, ...],
  99. live: bool,
  100. entity: str,
  101. project: str,
  102. run_id: str,
  103. skip_synced: bool,
  104. dry_run: bool,
  105. verbose: bool,
  106. n: int,
  107. ) -> None:
  108. """Upload .wandb files specified by PATHS.
  109. This is a beta re-implementation of `wandb sync`.
  110. It is not feature complete, not guaranteed to work, and may change
  111. in backward-incompatible ways in any release of wandb.
  112. PATHS can include .wandb files, run directories containing .wandb files,
  113. and "wandb" directories containing run directories.
  114. For example, to sync all runs in a directory:
  115. wandb beta sync ./wandb
  116. To sync a specific run:
  117. wandb beta sync ./wandb/run-20250813_124246-n67z9ude
  118. Or equivalently:
  119. wandb beta sync ./wandb/run-20250813_124246-n67z9ude/run-n67z9ude.wandb
  120. """
  121. from . import beta_sync
  122. beta_sync.sync(
  123. [pathlib.Path(path) for path in paths],
  124. live=live,
  125. entity=entity,
  126. project=project,
  127. run_id=run_id,
  128. dry_run=dry_run,
  129. skip_synced=skip_synced,
  130. verbose=verbose,
  131. parallelism=n,
  132. )