Skip to content

Commit

Permalink
legacy entrypoint deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
rb-determined-ai committed Oct 25, 2024
1 parent 28bb057 commit d08e1c7
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 8 deletions.
33 changes: 31 additions & 2 deletions harness/determined/exec/harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import faulthandler
import logging
import sys
import warnings
from typing import Iterator, Optional, Type

import determined as det
Expand Down Expand Up @@ -42,9 +43,9 @@ def main(train_entrypoint: str) -> int:
if hasattr(det.pytorch, "deepspeed") and issubclass(
trial_class, det.pytorch.deepspeed.DeepSpeedTrial
):
return _run_deepspeed_trial(trial_class, info)
return _run_deepspeed_trial(trial_class, info, train_entrypoint)
elif issubclass(trial_class, det.pytorch.PyTorchTrial):
return _run_pytorch_trial(trial_class, info)
return _run_pytorch_trial(trial_class, info, train_entrypoint)

# TODO: Don't include EnvContext object in the future high-level APIs for PyTorch or Keras.
# It was natural to create this big-blob-of-config object, but it was a mistake to pass it into
Expand Down Expand Up @@ -138,11 +139,25 @@ def main(train_entrypoint: str) -> int:
def _run_pytorch_trial(
trial_class: "Type[det.pytorch.PyTorchTrial]",
info: det.ClusterInfo,
train_entrypoint: str,
) -> int:
from determined import pytorch

det.common.set_logger(info.trial._debug)

# Only warn here if the user set a legacy entrypoint, not if we arrived here after user passed
# a --trial argument to a launcher.
if train_entrypoint == info.trial._config["entrypoint"]:
warnings.warn(
f"Support for legacy entrypoint format ({train_entrypoint}) has been deprecated in "
"Determined XXYYZZ and will be removed in a future version. You can keep your "
"PyTorchTrial, but please replace your model_def:TrialClass-style entrypoint "
"with a script-style entrypoint, and use the det.pytorch.Trainer() to train your "
"PyTorchTrial.",
FutureWarning,
stacklevel=2,
)

logger.debug("Starting harness.")

with maybe_periodic_stacktraces(info.trial._debug):
Expand Down Expand Up @@ -202,12 +217,26 @@ def _run_pytorch_trial(
def _run_deepspeed_trial(
trial_class: "Type[det.pytorch.deepspeed.DeepSpeedTrial]",
info: det.ClusterInfo,
train_entrypoint: str,
) -> int:
from determined import pytorch
from determined.pytorch import deepspeed as det_ds

det.common.set_logger(info.trial._debug)

# Only warn here if the user set a legacy entrypoint, not if we arrived here after user passed
# a --trial argument to a launcher.
if train_entrypoint == info.trial._config["entrypoint"]:
warnings.warn(
f"Support for legacy entrypoint format ({train_entrypoint}) has been deprecated in "
"Determined XXYYZZ and will be removed in a future version. You can keep your "
"DeepSpeedTrial, but please replace your model_def:TrialClass-style entrypoint "
"with a script-style entrypoint, and use the new det.pytorch.deepspeed.Trainer() "
"to train your DeepSpeedTrial.",
FutureWarning,
stacklevel=2,
)

logger.debug("Starting harness.")

with det_ds.init(
Expand Down
13 changes: 11 additions & 2 deletions harness/determined/launch/deepspeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import subprocess
import sys
import time
import warnings
from typing import Dict, List, Mapping, Optional

import deepspeed
Expand Down Expand Up @@ -375,8 +376,8 @@ def parse_args(args: List[str]) -> List[str]:
parser.add_argument(
"--trial",
help=(
"use a Trial class as the entrypoint to training. When --trial is used, the SCRIPT "
"positional argument must be omitted."
"(deprecated) use a Trial class as the entrypoint to training. When --trial is used, "
"the SCRIPT positional argument must be omitted."
),
)
# For training scripts.
Expand All @@ -396,6 +397,14 @@ def parse_args(args: List[str]) -> List[str]:
parser.print_usage()
print("error: extra arguments to --trial:", script, file=sys.stderr)
sys.exit(1)
warnings.warn(
"Support for --trial argument to determined.launch.deepspeed has been deprecated "
"in Determined XXYYZZ and will be removed in a future version. You can keep your "
"DeepSpeedTrial, but please replace your --trial argument with a script that uses the "
"new det.pytorch.deepspeed.Trainer() to train your DeepSpeedTrial.",
FutureWarning,
stacklevel=2,
)
script = det.util.legacy_trial_entrypoint_to_script(parsed.trial)
elif not script:
# There needs to be at least one script argument.
Expand Down
14 changes: 12 additions & 2 deletions harness/determined/launch/horovod.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import subprocess
import sys
import time
import warnings
from typing import List, Tuple

import determined as det
Expand Down Expand Up @@ -223,8 +224,8 @@ def parse_args(args: List[str]) -> Tuple[List[str], List[str], bool]:
parser.add_argument(
"--trial",
help=(
"use a Trial class as the entrypoint to training. When --trial is used, the SCRIPT "
"positional argument must be omitted."
"(deprecated) use a Trial class as the entrypoint to training. When --trial is used, "
"the SCRIPT positional argument must be omitted."
),
)
# For training scripts.
Expand Down Expand Up @@ -270,5 +271,14 @@ def parse_args(args: List[str]) -> Tuple[List[str], List[str], bool]:


if __name__ == "__main__":
warnings.warn(
"determined.launch.horovod has been deprecated in Determined XXYYZZ and will be "
"removed in a future version. For PyTorchTrial users, please switch to "
"determined.launch.torch_distributed instead. For TFKerasTrial users, please migrate "
"to the new det.keras.DeterminedCallback for training and use the new "
"determined.launch.tensorflow launcher with it.",
FutureWarning,
stacklevel=2,
)
hvd_args, script, autohorovod = parse_args(sys.argv[1:])
sys.exit(main(hvd_args, script, autohorovod))
18 changes: 16 additions & 2 deletions harness/determined/launch/torch_distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import subprocess
import sys
import warnings
from typing import List, Tuple

import determined as det
Expand Down Expand Up @@ -127,8 +128,8 @@ def parse_args(args: List[str]) -> Tuple[List[str], List[str]]:
parser.add_argument(
"--trial",
help=(
"use a Trial class as the entrypoint to training. When --trial is used, the SCRIPT "
"positional argument must be omitted."
"(deprecated) use a Trial class as the entrypoint to training. When --trial is used, "
"the SCRIPT positional argument must be omitted."
),
)
# For training scripts.
Expand All @@ -148,6 +149,19 @@ def parse_args(args: List[str]) -> Tuple[List[str], List[str]]:
parser.print_usage()
print("error: extra arguments to --trial:", script, file=sys.stderr)
sys.exit(1)
# We may have arrived here indirectly if the user specified a legacy entrypoint, in which
# case we have a warning for them in exec/harness.py. Only issue the warning if they
# explicitly configured the --trial argument.
info = det.get_cluster_info()
if info and "--trial" in info.trial._config["entrypoint"]:
warnings.warn(
"Support for --trial argument to determined.launch.torch_distributed has been "
"deprecated in Determined XXYYZZ and will be removed in a future version. You can "
"keep your PyTorchTrial, but please replace your --trial argument with a script "
"that uses the det.pytorch.Trainer() to train your PyTorchTrial.",
FutureWarning,
stacklevel=2,
)
script = det.util.legacy_trial_entrypoint_to_script(parsed.trial)
elif not script:
# There needs to be at least one script argument.
Expand Down

0 comments on commit d08e1c7

Please sign in to comment.