CoolFace
Apppublic

chendl/compositional_test

sourceHugging Faceupdated 3y agoView on Hugging Face
1likes
run_on_remote.py72 linesDownload Raw Back to examples
1#!/usr/bin/env python2# coding=utf-83# Copyright 2021 The HuggingFace Inc. team. All rights reserved.4#5# Licensed under the Apache License, Version 2.0 (the "License");6# you may not use this file except in compliance with the License.7# You may obtain a copy of the License at8#9#     http://www.apache.org/licenses/LICENSE-2.010#11# Unless required by applicable law or agreed to in writing, software12# distributed under the License is distributed on an "AS IS" BASIS,13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14# See the License for the specific language governing permissions and15# limitations under the License.16 17import argparse18import shlex19 20import runhouse as rh21 22 23if __name__ == "__main__":24    # Refer to https://runhouse-docs.readthedocs-hosted.com/en/main/rh_primitives/cluster.html#hardware-setup for cloud access25    # setup instructions, if using on-demand hardware26 27    # If user passes --user <user> --host <host> --key_path <key_path> <example> <args>, fill them in as BYO cluster28    # If user passes --instance <instance> --provider <provider> <example> <args>, fill them in as on-demand cluster29    # Throw an error if user passes both BYO and on-demand cluster args30    # Otherwise, use default values31    parser = argparse.ArgumentParser()32    parser.add_argument("--user", type=str, default="ubuntu")33    parser.add_argument("--host", type=str, default="localhost")34    parser.add_argument("--key_path", type=str, default=None)35    parser.add_argument("--instance", type=str, default="V100:1")36    parser.add_argument("--provider", type=str, default="cheapest")37    parser.add_argument("--use_spot", type=bool, default=False)38    parser.add_argument("--example", type=str, default="pytorch/text-generation/run_generation.py")39    args, unknown = parser.parse_known_args()40    if args.host != "localhost":41        if args.instance != "V100:1" or args.provider != "cheapest":42            raise ValueError("Cannot specify both BYO and on-demand cluster args")43        cluster = rh.cluster(44            name="rh-cluster", ips=[args.host], ssh_creds={"ssh_user": args.user, "ssh_private_key": args.key_path}45        )46    else:47        cluster = rh.cluster(48            name="rh-cluster", instance_type=args.instance, provider=args.provider, use_spot=args.use_spot49        )50    example_dir = args.example.rsplit("/", 1)[0]51 52    # Set up remote environment53    cluster.install_packages(["pip:./"])  # Installs transformers from local source54    # Note transformers is copied into the home directory on the remote machine, so we can install from there55    cluster.run([f"pip install -r transformers/examples/{example_dir}/requirements.txt"])56    cluster.run(["pip install torch --upgrade --extra-index-url https://download.pytorch.org/whl/cu117"])57 58    # Run example. You can bypass the CLI wrapper and paste your own code here.59    cluster.run([f'python transformers/examples/{args.example} {" ".join(shlex.quote(arg) for arg in unknown)}'])60 61    # Alternatively, we can just import and run a training function (especially if there's no wrapper CLI):62    # from my_script... import train63    # reqs = ['pip:./', 'torch', 'datasets', 'accelerate', 'evaluate', 'tqdm', 'scipy', 'scikit-learn', 'tensorboard']64    # launch_train_gpu = rh.function(fn=train,65    #                                system=gpu,66    #                                reqs=reqs,67    #                                name='train_bert_glue')68    #69    # We can pass in arguments just like we would to a function:70    # launch_train_gpu(num_epochs = 3, lr = 2e-5, seed = 42, batch_size = 1671    #                  stream_logs=True)72