|
40 | 40 | "## Prequisites"
|
41 | 41 | ]
|
42 | 42 | },
|
| 43 | + { |
| 44 | + "cell_type": "markdown", |
| 45 | + "metadata": {}, |
| 46 | + "source": [ |
| 47 | + "### Use below commands only if you want to make changes to the simulation application (Robomaker code changes)" |
| 48 | + ] |
| 49 | + }, |
| 50 | + { |
| 51 | + "cell_type": "code", |
| 52 | + "execution_count": null, |
| 53 | + "metadata": {}, |
| 54 | + "outputs": [], |
| 55 | + "source": [ |
| 56 | + "# #\n", |
| 57 | + "# # Run these commands if you want to modify the simapp\n", |
| 58 | + "# #\n", |
| 59 | + "# # Clean the build directory if present\n", |
| 60 | + "# !python3 sim_app_bundler.py --clean\n", |
| 61 | + "\n", |
| 62 | + "# # Download Robomaker simApp from the deepracer public s3 bucket\n", |
| 63 | + "# simulation_application_bundle_location = \"s3://deepracer-managed-resources-us-east-1/deepracer-simapp-notebook.tar.gz\"\n", |
| 64 | + "# !aws s3 cp {simulation_application_bundle_location} ./\n", |
| 65 | + "\n", |
| 66 | + "# # Untar the simapp bundle\n", |
| 67 | + "# !python3 sim_app_bundler.py --untar ./deepracer-simapp.tar.gz\n", |
| 68 | + "\n", |
| 69 | + "# # Now modify the simapp from build directory and run this command.\n", |
| 70 | + "\n", |
| 71 | + "# # Most of the simapp files can be found here (Robomaker changes)\n", |
| 72 | + "# # bundle/opt/install/sagemaker_rl_agent/lib/python3.5/site-packages/\n", |
| 73 | + "# # bundle/opt/install/deepracer_simulation_environment/share/deepracer_simulation_environment/\n", |
| 74 | + "# # bundle/opt/install/deepracer_simulation_environment/lib/deepracer_simulation_environment/\n", |
| 75 | + "\n", |
| 76 | + "# # Copying the notebook src/markov changes to the simapp (For sagemaker container)\n", |
| 77 | + "# !rsync -av ./src/markov/ ./build/simapp/bundle/opt/install/sagemaker_rl_agent/lib/python3.5/site-packages/markov\n", |
| 78 | + "\n", |
| 79 | + "# !python3 sim_app_bundler.py --tar" |
| 80 | + ] |
| 81 | + }, |
43 | 82 | {
|
44 | 83 | "cell_type": "markdown",
|
45 | 84 | "metadata": {},
|
|
246 | 285 | "outputs": [],
|
247 | 286 | "source": [
|
248 | 287 | "%%time\n",
|
| 288 | + "from copy_to_sagemaker_container import get_sagemaker_docker, copy_to_sagemaker_container, get_custom_image_name\n", |
249 | 289 | "cpu_or_gpu = 'gpu' if instance_type.startswith('ml.p') else 'cpu'\n",
|
250 | 290 | "repository_short_name = \"sagemaker-docker-%s\" % cpu_or_gpu\n",
|
251 |
| - "docker_build_args = {\n", |
252 |
| - " 'CPU_OR_GPU': cpu_or_gpu, \n", |
253 |
| - " 'AWS_REGION': boto3.Session().region_name,\n", |
254 |
| - "}\n", |
255 |
| - "custom_image_name = build_and_push_docker_image(repository_short_name, build_args=docker_build_args)\n", |
256 |
| - "print(\"Using ECR image %s\" % custom_image_name)" |
| 291 | + "custom_image_name = get_custom_image_name(repository_short_name)\n", |
| 292 | + "try:\n", |
| 293 | + " print(\"Copying files from your notebook to existing sagemaker container\")\n", |
| 294 | + " sagemaker_docker_id = get_sagemaker_docker(repository_short_name)\n", |
| 295 | + " copy_to_sagemaker_container(sagemaker_docker_id, repository_short_name)\n", |
| 296 | + "except Exception as e:\n", |
| 297 | + " print(\"Creating sagemaker container\")\n", |
| 298 | + " docker_build_args = {\n", |
| 299 | + " 'CPU_OR_GPU': cpu_or_gpu, \n", |
| 300 | + " 'AWS_REGION': boto3.Session().region_name,\n", |
| 301 | + " }\n", |
| 302 | + " custom_image_name = build_and_push_docker_image(repository_short_name, build_args=docker_build_args)\n", |
| 303 | + " print(\"Using ECR image %s\" % custom_image_name)" |
| 304 | + ] |
| 305 | + }, |
| 306 | + { |
| 307 | + "cell_type": "markdown", |
| 308 | + "metadata": {}, |
| 309 | + "source": [ |
| 310 | + "### Clean the docker images\n", |
| 311 | + "Remove this only when you want to completely remove the docker or clean up the space of the sagemaker instance" |
| 312 | + ] |
| 313 | + }, |
| 314 | + { |
| 315 | + "cell_type": "code", |
| 316 | + "execution_count": null, |
| 317 | + "metadata": {}, |
| 318 | + "outputs": [], |
| 319 | + "source": [ |
| 320 | + "# !docker rm -f $(docker ps -a -q);\n", |
| 321 | + "# !docker rmi -f $(docker images -q);" |
257 | 322 | ]
|
258 | 323 | },
|
259 | 324 | {
|
|
280 | 345 | "# If this is not present. Use the default VPC connnection\n",
|
281 | 346 | "#\n",
|
282 | 347 | "deepracer_security_groups = [group[\"GroupId\"] for group in ec2.describe_security_groups()['SecurityGroups']\\\n",
|
283 |
| - " if group['GroupName'].startswith(\"deepracer-vpc\")]\n", |
| 348 | + " if group['GroupName'].startswith(\"aws-deepracer-\")]\n", |
| 349 | + "\n", |
| 350 | + "# deepracer_security_groups = False\n", |
284 | 351 | "if(deepracer_security_groups):\n",
|
285 |
| - " print(\"Using the DeepRacer VPC stacks\")\n", |
| 352 | + " print(\"Using the DeepRacer VPC stacks. This will be created if you run one training job from console.\")\n", |
286 | 353 | " deepracer_vpc = [vpc['VpcId'] for vpc in ec2.describe_vpcs()['Vpcs'] \\\n",
|
287 | 354 | " if \"Tags\" in vpc for val in vpc['Tags'] \\\n",
|
288 | 355 | " if val['Value'] == 'deepracer-vpc'][0]\n",
|
|
351 | 418 | " display(Markdown(generate_help_for_s3_endpoint_permissions(role)))\n",
|
352 | 419 | " raise e\n",
|
353 | 420 | " else:\n",
|
354 |
| - " display(Markdown(create_s3_endpoint_manually(aws_region, default_vpc)))\n", |
| 421 | + " display(Markdown(create_s3_endpoint_manually(aws_region, deepracer_vpc)))\n", |
355 | 422 | " raise e\n",
|
356 | 423 | "\n",
|
357 | 424 | "if CREATE_ROUTE_TABLE:\n",
|
|
579 | 646 | "metadata": {},
|
580 | 647 | "outputs": [],
|
581 | 648 | "source": [
|
582 |
| - "# Download Robomaker simApp for the deepracer public s3 bucket\n", |
583 |
| - "simulation_application_bundle_location = \"s3://deepracer-managed-resources-us-east-1/deepracer-simapp.tar.gz\"\n", |
584 |
| - "!aws s3 cp {simulation_application_bundle_location} ./\n", |
| 649 | + "if not os.path.exists('./build/output.tar.gz'):\n", |
| 650 | + " print(\"Using the latest simapp from public s3 bucket\")\n", |
| 651 | + " # Download Robomaker simApp for the deepracer public s3 bucket\n", |
| 652 | + " simulation_application_bundle_location = \"s3://deepracer-managed-resources-us-east-1/deepracer-simapp-notebook.tar.gz\"\n", |
| 653 | + " !aws s3 cp {simulation_application_bundle_location} ./\n", |
585 | 654 | "\n",
|
586 |
| - "# Remove if the Robomaker sim-app is present in s3 bucket\n", |
587 |
| - "!aws s3 rm s3://{s3_bucket}/{robomaker_s3_key}\n", |
| 655 | + " # Remove if the Robomaker sim-app is present in s3 bucket\n", |
| 656 | + " !aws s3 rm s3://{s3_bucket}/{robomaker_s3_key}\n", |
588 | 657 | "\n",
|
589 |
| - "# Uploading the Robomaker SimApp to your S3 bucket\n", |
590 |
| - "!aws s3 cp ./deepracer-simapp.tar.gz s3://{s3_bucket}/{robomaker_s3_key}\n", |
591 |
| - " \n", |
592 |
| - "# Cleanup the locally downloaded version of SimApp\n", |
593 |
| - "!rm deepracer-simapp.tar.gz\n" |
| 658 | + " # Uploading the Robomaker SimApp to your S3 bucket\n", |
| 659 | + " !aws s3 cp ./deepracer-simapp-notebook.tar.gz s3://{s3_bucket}/{robomaker_s3_key}\n", |
| 660 | + "\n", |
| 661 | + " # Cleanup the locally downloaded version of SimApp\n", |
| 662 | + " !rm deepracer-simapp-notebook.tar.gz\n", |
| 663 | + "else:\n", |
| 664 | + " print(\"Using the simapp from build directory\")\n", |
| 665 | + " !aws s3 cp ./build/output.tar.gz s3://{s3_bucket}/{robomaker_s3_key}" |
594 | 666 | ]
|
595 | 667 | },
|
596 | 668 | {
|
|
664 | 736 | " \"securityGroups\": deepracer_security_groups,\n",
|
665 | 737 | " \"assignPublicIp\": True}\n",
|
666 | 738 | "\n",
|
667 |
| - "client_request_token = strftime(\"%Y-%m-%d-%H-%M-%S\", gmtime())\n", |
668 |
| - "\n", |
669 | 739 | "responses = []\n",
|
670 | 740 | "for job_no in range(num_simulation_workers):\n",
|
| 741 | + " client_request_token = strftime(\"%Y-%m-%d-%H-%M-%S\", gmtime())\n", |
671 | 742 | " response = robomaker.create_simulation_job(iamRole=sagemaker_role,\n",
|
672 | 743 | " clientRequestToken=client_request_token,\n",
|
673 | 744 | " maxJobDurationInSeconds=job_duration_in_seconds,\n",
|
|
908 | 979 | "# model_output = \"s3://{}/{}\".format(s3_bucket, s3_bucket)\n",
|
909 | 980 | "# !aws s3 rm --recursive {model_output}"
|
910 | 981 | ]
|
911 |
| - }, |
912 |
| - { |
913 |
| - "cell_type": "markdown", |
914 |
| - "metadata": {}, |
915 |
| - "source": [ |
916 |
| - "### Clean the docker images\n", |
917 |
| - "Remove this only when you want to completely remove the docker or clean up the space of the sagemaker instance" |
918 |
| - ] |
919 |
| - }, |
920 |
| - { |
921 |
| - "cell_type": "code", |
922 |
| - "execution_count": null, |
923 |
| - "metadata": {}, |
924 |
| - "outputs": [], |
925 |
| - "source": [ |
926 |
| - "# !docker rmi -f $(docker images -q)" |
927 |
| - ] |
928 | 982 | }
|
929 | 983 | ],
|
930 | 984 | "metadata": {
|
|
0 commit comments