Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Menggunakan CLI
hyp create hyp-pytorch-job \ --version 1.0 \ --job-name test-pytorch-job \ --image pytorch/pytorch:latest \ --command '["python", "train.py"]' \ --args '["--epochs", "10", "--batch-size", "32"]' \ --environment '{"PYTORCH_CUDA_ALLOC_CONF": "max_split_size_mb:32"}' \ --pull-policy "IfNotPresent" \ --instance-type ml.p4d.24xlarge \ --tasks-per-node 8 \ --label-selector '{"accelerator": "nvidia", "network": "efa"}' \ --deep-health-check-passed-nodes-only true \ --scheduler-type "kueue" \ --queue-name "training-queue" \ --priority "high" \ --max-retry 3 \ --volumes '["data-vol", "model-vol", "checkpoint-vol"]' \ --persistent-volume-claims '["shared-data-pvc", "model-registry-pvc"]' \ --output-s3-uri s3://my-bucket/model-artifacts
from sagemaker.hyperpod import HyperPodPytorchJob from sagemaker.hyperpod.job import ReplicaSpec, Template, Spec, Container, Resources, RunPolicy, Metadata # Define job specifications nproc_per_node = "1" # Number of processes per node replica_specs = [ ReplicaSpec ( name = "pod", # Replica name template = Template ( spec = Spec ( containers = [ Container ( # Container name name="container-name", # Training image image="448049793756.dkr.ecr.us-west-2.amazonaws.com/ptjob:mnist", # Always pull image image_pull_policy="Always", resources=Resources\ ( # No GPUs requested requests={"nvidia.com/gpu": "0"}, # No GPU limit limits={"nvidia.com/gpu": "0"}, ), # Command to run command=["python", "train.py"], # Script arguments args=["--epochs", "10", "--batch-size", "32"], ) ] ) ), ) ] # Keep pods after completion run_policy = RunPolicy(clean_pod_policy="None") # Create and start the PyTorch job pytorch_job = HyperPodPytorchJob ( # Job name metadata = Metadata(name="demo"), # Processes per node nproc_per_node = nproc_per_node, # Replica specifications replica_specs = replica_specs, # Run policy run_policy = run_policy, # S3 location for artifacts output_s3_uri="s3://my-bucket/model-artifacts" ) # Launch the job pytorch_job.create()
Menggunakan CLI
# Check job status hyp list hyp-pytorch-job # Get detailed information hyp describe hyp-pytorch-job --job-name test-pytorch-job # View logs hyp get-logs hyp-pytorch-job \ --pod-name test-pytorch-job-pod-0 \ --job-name test-pytorch-job
print("List all pods created for this job:") print(pytorch_job.list_pods()) print("Check the logs from pod0:") print(pytorch_job.get_logs_from_pod(pod_name="demo-pod-0")) print("List all HyperPodPytorchJobs:") print(HyperPodPytorchJob.list()) print("Describe job:") print(HyperPodPytorchJob.get(name="demo").model_dump()) pytorch_job.refresh() print(pytorch_job.status.model_dump())
Langkah selanjutnya