Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[train] fix transformers example for multi-gpu #24832

Merged
merged 5 commits into from Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion python/ray/train/BUILD
Expand Up @@ -49,7 +49,19 @@ py_test(
)

py_test(
name = "transformers_example",
name = "transformers_example_gpu",
size = "large",
main = "examples/transformers/transformers_example.py",
srcs = ["examples/transformers/transformers_example.py"],
tags = ["team:ml", "exclusive", "tune", "gpu_only"],
deps = [":train_lib"],
args = ["--model_name_or_path=bert-base-cased", "--task_name=mrpc",
"--max_length=32", "--per_device_train_batch_size=64",
"--max_train_steps=2", "--start_local", "--num_workers=2", "--use_gpu"]
)

py_test(
name = "transformers_example_cpu",
size = "large",
main = "examples/transformers/transformers_example.py",
srcs = ["examples/transformers/transformers_example.py"],
Expand Down
2 changes: 2 additions & 0 deletions python/ray/train/examples/transformers/cluster.yaml
Expand Up @@ -19,6 +19,7 @@ available_node_types:
ray.head.default:
min_workers: 0
max_workers: 0
resources: {}
node_config:
InstanceType: g3.8xlarge
ImageId: latest_dlami
Expand All @@ -33,6 +34,7 @@ available_node_types:
ray.worker.default:
min_workers: 3
max_workers: 3
resources: {}
node_config:
InstanceType: g3.8xlarge
ImageId: latest_dlami
Expand Down
Expand Up @@ -228,10 +228,14 @@ def parse_args():


def train_func(config: Dict[str, Any]):
# Accelerator reads from this environment variable for GPU placement.
os.environ["LOCAL_RANK"] = str(ray.train.local_rank())
os.environ["WORLD_SIZE"] = str(ray.train.world_size())

args = config["args"]
# Initialize the accelerator. We will let the accelerator handle device
# placement for us in this example.
accelerator = Accelerator()
accelerator = Accelerator(cpu=not args.use_gpu)
# Make one log on every process with the configuration for debugging.
logging.basicConfig(
format="%(asctime)s - %(levelname)s - %(name)s - %(message)s",
Expand Down