Ejemplo n.º 1
0
        ///GENMHASH:A851295FCC0E9F4FE107D9566C40A6D0:444BB1540F15B3A5BECC3E92D812699B
        public BatchAIJobImpl WithExistingCluster(IBatchAICluster cluster)
        {
            parent = cluster;
            createParameters.Cluster = new Models.ResourceId(cluster.Id);

            return(this);
        }
Ejemplo n.º 2
0
        public void CanCreateJob()
        {
            using (var context = FluentMockContext.Start(GetType().FullName))
            {
                string groupName   = SdkContext.RandomResourceName("rg", 10);
                string clusterName = SdkContext.RandomResourceName("cluster", 15);
                string userName    = "******";

                var manager = TestHelper.CreateBatchAIManager();

                IBatchAICluster cluster = manager.BatchAIClusters.Define(clusterName)
                                          .WithRegion(REGION)
                                          .WithNewResourceGroup(groupName)
                                          .WithVMSize(VirtualMachineSizeTypes.StandardD1V2.Value)
                                          .WithUserName(userName)
                                          .WithPassword("MyPassword")
                                          .WithAutoScale(1, 1)
                                          .Create();
                Assert.Equal(AllocationState.Steady, cluster.AllocationState);
                Assert.Equal(userName, cluster.AdminUserName);
                IBatchAIJob job = manager.BatchAIJobs.Define("myJob")
                                  .WithExistingClusterId(cluster.Id)
                                  .WithNodeCount(1)
                                  .WithStdOutErrPathPrefix("$AZ_BATCHAI_MOUNT_ROOT/azurefileshare")
                                  .DefineCognitiveToolkit()
                                  .WithPythonScriptFile("$AZ_BATCHAI_INPUT_SAMPLE/ConvNet_MNIST.py")
                                  .WithCommandLineArgs("$AZ_BATCHAI_INPUT_SAMPLE $AZ_BATCHAI_OUTPUT_MODEL")
                                  .Attach()
                                  .WithInputDirectory("SAMPLE", "$AZ_BATCHAI_MOUNT_ROOT/azurefileshare/mnistcntksample")
                                  .WithOutputDirectory("MODEL", "$AZ_BATCHAI_MOUNT_ROOT/azurefileshare/model")
                                  .DefineOutputDirectory("OUTPUT")
                                  .WithPathPrefix("$AZ_BATCHAI_MOUNT_ROOT/azurefileshare/output")
                                  .WithCreateNew(true)
                                  .WithPathSuffix("suffix")
                                  .Attach()
                                  .WithContainerImage("microsoft/cntk:2.1-gpu-python3.5-cuda8.0-cudnn6.0")
                                  .Create();
                Assert.Equal(groupName, job.ResourceGroupName);
                Assert.Equal(2, job.OutputDirectories.Count);
                OutputDirectory outputDirectory = null;
                foreach (OutputDirectory directory in job.OutputDirectories)
                {
                    if ("OUTPUT".Equals(directory.Id.ToUpper()))
                    {
                        outputDirectory = directory;
                        break;
                    }
                }
                Assert.NotNull(outputDirectory);
                Assert.Equal("suffix", outputDirectory.PathSuffix.ToLower());

                job.Refresh();
                Assert.Equal(groupName, job.ResourceGroupName);

                manager.ResourceManager.ResourceGroups.BeginDeleteByName(groupName);
            }
        }
Ejemplo n.º 3
0
        public override async Task <Microsoft.Azure.Management.BatchAI.Fluent.IBatchAIJob> CreateResourceAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            if (parent == null)
            {
                parent = await Manager.BatchAIClusters.GetByIdAsync(createParameters.Cluster.Id, cancellationToken);
            }
            createParameters.Location = parent.RegionName;
            var inner = await Manager.Inner.Jobs.CreateAsync(parent.ResourceGroupName, this.Name, createParameters, cancellationToken);

            SetInner(inner);
            return(this);
        }
        public void CanCreateJob()
        {
            using (var context = FluentMockContext.Start(GetType().FullName))
            {
                string groupName          = SdkContext.RandomResourceName("rg", 10);
                string clusterName        = SdkContext.RandomResourceName("cluster", 15);
                string saName             = SdkContext.RandomResourceName("sa", 15);
                string shareName          = "myfileshare";
                string shareMountPath     = "azurefileshare";
                string blobFileSystemPath = "myblobsystem";
                string containerName      = "mycontainer";
                string userName           = "******";
                string storageAccountKey  = "dummy_key";
                string fileShareUri       = "dummy_uri";

                var manager = TestHelper.CreateBatchAIManager();

                IBatchAICluster cluster = manager.BatchAIClusters.Define(clusterName)
                                          .WithRegion(REGION)
                                          .WithNewResourceGroup(groupName)
                                          .WithVMSize(VirtualMachineSizeTypes.StandardD1V2.Value)
                                          .WithUserName(userName)
                                          .WithPassword("MyPassword")
                                          .WithAutoScale(1, 1)
                                          .Create();
                Assert.Equal(AllocationState.Steady, cluster.AllocationState);
                Assert.Equal(userName, cluster.AdminUserName);
                IBatchAIJob job = cluster.Jobs.Define("myJob")
                                  .WithRegion(REGION)
                                  .WithNodeCount(1)
                                  .WithStdOutErrPathPrefix("$AZ_BATCHAI_MOUNT_ROOT/azurefileshare")
                                  .DefineCognitiveToolkit()
                                  .WithPythonScriptFile("$AZ_BATCHAI_INPUT_SAMPLE/ConvNet_MNIST.py")
                                  .WithCommandLineArgs("$AZ_BATCHAI_INPUT_SAMPLE $AZ_BATCHAI_OUTPUT_MODEL")
                                  .Attach()
                                  .WithInputDirectory("SAMPLE", "$AZ_BATCHAI_MOUNT_ROOT/azurefileshare/mnistcntksample")
                                  .WithOutputDirectory("MODEL", "$AZ_BATCHAI_MOUNT_ROOT/azurefileshare/model")
                                  .WithContainerImage("microsoft/cntk:2.1-gpu-python3.5-cuda8.0-cudnn6.0")
                                  .Create();
                Assert.Equal(groupName, job.ResourceGroupName);

                job.Refresh();
                Assert.Equal(groupName, job.ResourceGroupName);

                manager.ResourceManager.ResourceGroups.DeleteByName(groupName);
            }
        }
Ejemplo n.º 5
0
        public void CreateUpdate()
        {
            using (var context = FluentMockContext.Start(GetType().FullName))
            {
                string groupName          = SdkContext.RandomResourceName("rg", 10);
                string clusterName        = SdkContext.RandomResourceName("cluster", 15);
                string vnetName           = SdkContext.RandomResourceName("vnet", 10);
                string saName             = SdkContext.RandomResourceName("sa", 15);
                string shareMountPath     = "azurefileshare";
                string blobFileSystemPath = "myblobsystem";
                string containerName      = "mycontainer";
                string userName           = "******";
                string storageAccountKey  = "dummy_key";
                string fileShareUri       = "dummy_uri";
                string subnetName         = "MySubnet";

                var manager        = TestHelper.CreateBatchAIManager();
                var networkManager = TestHelper.CreateNetworkManager();

                INetwork network = networkManager.Networks.Define(vnetName)
                                   .WithRegion(REGION)
                                   .WithNewResourceGroup(groupName)
                                   .WithAddressSpace("192.168.0.0/16")
                                   .WithSubnet(subnetName, "192.168.200.0/24")
                                   .Create();

                IBatchAICluster cluster = manager.BatchAIClusters.Define(clusterName)
                                          .WithRegion(REGION)
                                          .WithNewResourceGroup(groupName)
                                          .WithVMSize(VirtualMachineSizeTypes.StandardD1V2.Value)
                                          .WithUserName(userName)
                                          .WithPassword("MyPassword")
                                          .WithAutoScale(1, 1)
                                          .WithLowPriority()
                                          .DefineSetupTask()
                                          .WithCommandLine("echo Hello World!")
                                          .WithStdOutErrPath("./outputpath")
                                          .Attach()
                                          .DefineAzureFileShare()
                                          .WithStorageAccountName(saName)
                                          .WithAzureFileUrl(fileShareUri)
                                          .WithRelativeMountPath(shareMountPath)
                                          .WithAccountKey(storageAccountKey)
                                          .Attach()
                                          .DefineAzureBlobFileSystem()
                                          .WithStorageAccountName(saName)
                                          .WithContainerName(containerName)
                                          .WithRelativeMountPath(blobFileSystemPath)
                                          .WithAccountKey(storageAccountKey)
                                          .Attach()
                                          .WithVirtualMachineImage("microsoft-ads", "linux-data-science-vm-ubuntu", "linuxdsvmubuntu")
                                          .WithSubnet(network.Id, subnetName)
                                          .WithAppInsightsComponentId("appinsightsId")
                                          .WithInstrumentationKey("appInsightsKey")
                                          .WithTag("tag1", "value1")
                                          .Create();
                Assert.Equal(AllocationState.Steady, cluster.AllocationState);
                Assert.Equal(userName, cluster.AdminUserName);
                Assert.Equal(VmPriority.Lowpriority, cluster.VMPriority);
                Assert.Equal(1, cluster.NodeSetup.MountVolumes.AzureFileShares.Count);
                Assert.Equal(shareMountPath, cluster.NodeSetup.MountVolumes.AzureFileShares.ElementAt(0).RelativeMountPath);
                Assert.Equal(1, cluster.NodeSetup.MountVolumes.AzureBlobFileSystems.Count);
                Assert.Equal(blobFileSystemPath, cluster.NodeSetup.MountVolumes.AzureBlobFileSystems.ElementAt(0).RelativeMountPath);
                Assert.Equal(network.Id + "/subnets/" + subnetName, cluster.Subnet.Id);
                Assert.Equal("appinsightsId", cluster.NodeSetup.PerformanceCountersSettings.AppInsightsReference.Component.Id);
                Assert.Equal("linux-data-science-vm-ubuntu", cluster.VirtualMachineConfiguration.ImageReference.Offer);

                cluster.Update()
                .WithAutoScale(1, 2, 2)
                .WithTag("tag1", "value2")
                .Apply();
                Assert.Equal(2, cluster.ScaleSettings.AutoScale.MaximumNodeCount);
                string tag1;
                Assert.True(cluster.Tags.TryGetValue("tag1", out tag1));
                Assert.Equal("value2", tag1);

                manager.ResourceManager.ResourceGroups.DeleteByName(groupName);
            }
        }
 /// <summary>
 /// Sets Batch AI cluster for the job.
 /// </summary>
 /// <param name="cluster">Batch AI cluster to run the job.</param>
 /// <return>The next stage of the definition.</return>
 BatchAIJob.Definition.IWithNodeCount BatchAIJob.Definition.IWithCluster.WithExistingCluster(IBatchAICluster cluster)
 {
     return(this.WithExistingCluster(cluster));
 }
        /**
         * Azure Batch AI sample.
         *  - Create Storage account and Azure file share
         *  - Upload sample data to Azure file share
         *  - Create a workspace and experiment
         *  - Create Batch AI cluster that uses Azure file share to host the training data and scripts for the learning job
         *  - Create Microsoft Cognitive Toolkit job to run on the cluster
         *  - Wait for job to complete
         *  - Get output files
         */
        public static void RunSample(IAzure azure)
        {
            string saName         = SdkContext.RandomResourceName("sa", 10);
            string rgName         = SdkContext.RandomResourceName("rg", 10);
            string workspaceName  = SdkContext.RandomResourceName("ws", 10);
            string experimentName = SdkContext.RandomResourceName("exp", 10);
            string sampleDataPath = Environment.GetEnvironmentVariable("SAMPLE_DATA_PATH");
            Region region         = Region.USWest2;
            string shareName      = SdkContext.RandomResourceName("fs", 20);
            string clusterName    = SdkContext.RandomResourceName("cluster", 15);
            string userName       = Utilities.CreateUsername();
            string sharePath      = "mnistcntksample";

            try
            {
                //=============================================================
                // Create a new storage account and an Azure file share resource
                Utilities.Log("Creating a storage account...");
                IStorageAccount storageAccount = azure.StorageAccounts.Define(saName)
                                                 .WithRegion(region)
                                                 .WithNewResourceGroup(rgName)
                                                 .Create();
                Utilities.Log("Created storage account.");
                Utilities.PrintStorageAccount(storageAccount);

                StorageAccountKey storageAccountKey = storageAccount.GetKeys().First();

                Utilities.Log("Creating Azure File share...");
                var cloudFileShare = CloudStorageAccount.Parse($"DefaultEndpointsProtocol=https;AccountName={saName};AccountKey={storageAccountKey.Value};EndpointSuffix=core.windows.net")
                                     .CreateCloudFileClient()
                                     .GetShareReference(shareName);
                cloudFileShare.CreateAsync().GetAwaiter().GetResult();
                Utilities.Log("Created Azure File share.");

                //=============================================================
                // Upload sample data to Azure file share

                //Get a reference to the root directory for the share.
                CloudFileDirectory rootDir = cloudFileShare.GetRootDirectoryReference();

                //Get a reference to the sampledir directory
                Utilities.Log("Creating directory and uploading data files...");
                CloudFileDirectory sampleDir = rootDir.GetDirectoryReference(sharePath);
                sampleDir.CreateAsync().GetAwaiter().GetResult();

                rootDir.GetFileReference("Train-28x28_cntk_text.txt").UploadFromFileAsync(sampleDataPath + "/Train-28x28_cntk_text.txt").GetAwaiter().GetResult();
                rootDir.GetFileReference("Test-28x28_cntk_text.txt").UploadFromFileAsync(sampleDataPath + "/Test-28x28_cntk_text.txt").GetAwaiter().GetResult();
                rootDir.GetFileReference("ConvNet_MNIST.py").UploadFromFileAsync(sampleDataPath + "/ConvNet_MNIST.py").GetAwaiter().GetResult();
                Utilities.Log("Data files uploaded.");
                //=============================================================
                // Create a workspace and experiment
                IBatchAIWorkspace workspace = azure.BatchAIWorkspaces.Define(workspaceName)
                                              .WithRegion(region)
                                              .WithNewResourceGroup(rgName)
                                              .Create();
                IBatchAIExperiment experiment = workspace.CreateExperiment(experimentName);


                //=============================================================
                // Create Batch AI cluster that uses Azure file share to host the training data and scripts for the learning job
                Utilities.Log("Creating Batch AI cluster...");
                IBatchAICluster cluster = workspace.Clusters.Define(clusterName)
                                          .WithVMSize(VirtualMachineSizeTypes.StandardNC6.Value)
                                          .WithUserName(userName)
                                          .WithPassword("MyPassword")
                                          .WithAutoScale(0, 2)
                                          .DefineAzureFileShare()
                                          .WithStorageAccountName(saName)
                                          .WithAzureFileUrl(cloudFileShare.Uri.ToString())
                                          .WithRelativeMountPath("azurefileshare")
                                          .WithAccountKey(storageAccountKey.Value)
                                          .Attach()
                                          .Create();
                Utilities.Log("Created Batch AI cluster.");
                Utilities.Print(cluster);

                // =============================================================
                // Create Microsoft Cognitive Toolkit job to run on the cluster
                Utilities.Log("Creating Batch AI job...");
                IBatchAIJob job = experiment.Jobs.Define("myJob")
                                  .WithExistingCluster(cluster)
                                  .WithNodeCount(1)
                                  .WithStdOutErrPathPrefix("$AZ_BATCHAI_MOUNT_ROOT/azurefileshare")
                                  .DefineCognitiveToolkit()
                                  .WithPythonScriptFile("$AZ_BATCHAI_MOUNT_ROOT/azurefileshare/ConvNet_MNIST.py")
                                  .WithCommandLineArgs("$AZ_BATCHAI_MOUNT_ROOT/azurefileshare $AZ_BATCHAI_OUTPUT_MODEL")
                                  .Attach()
                                  .WithOutputDirectory("MODEL", "$AZ_BATCHAI_MOUNT_ROOT/azurefileshare/model")
                                  .WithContainerImage("microsoft/cntk:2.1-gpu-python3.5-cuda8.0-cudnn6.0")
                                  .Create();
                Utilities.Log("Created Batch AI job.");
                Utilities.Print(job);

                // =============================================================
                // Wait for job results

                // Wait for job to start running
                Utilities.Log("Waiting for Batch AI job to start running...");
                while (ExecutionState.Queued.Equals(job.ExecutionState))
                {
                    SdkContext.DelayProvider.Delay(5000);
                    job.Refresh();
                }

                // Wait for job to complete and job output to become available
                Utilities.Log("Waiting for Batch AI job to complete...");
                while (!(ExecutionState.Succeeded.Equals(job.ExecutionState) || ExecutionState.Failed.Equals(job.ExecutionState)))
                {
                    SdkContext.DelayProvider.Delay(5000);
                    job.Refresh();
                }

                // =============================================================
                // Get output files

                // Print stdout and stderr
                foreach (var outputFile in job.ListFiles("stdouterr"))
                {
                    Utilities.Log(Utilities.CheckAddress(outputFile.DownloadUrl));
                }
                // List model output files
                foreach (var outputFile in job.ListFiles("MODEL"))
                {
                    Utilities.Log(outputFile.DownloadUrl);
                }
            }
            finally
            {
                try
                {
                    Utilities.Log("Deleting Resource Group: " + rgName);
                    azure.ResourceGroups.BeginDeleteByName(rgName);
                    Utilities.Log("Deleted Resource Group: " + rgName);
                }
                catch (Exception)
                {
                    Utilities.Log("Did not create any resources in Azure. No clean up is necessary");
                }
            }
        }
        public void CreateUpdate()
        {
            using (var context = FluentMockContext.Start(GetType().FullName))
            {
                string groupName          = SdkContext.RandomResourceName("rg", 10);
                string clusterName        = SdkContext.RandomResourceName("cluster", 15);
                string saName             = SdkContext.RandomResourceName("sa", 15);
                string shareName          = "myfileshare";
                string shareMountPath     = "azurefileshare";
                string blobFileSystemPath = "myblobsystem";
                string containerName      = "mycontainer";
                string userName           = "******";
                string storageAccountKey  = "dummy_key";
                string fileShareUri       = "dummy_uri";

                var manager = TestHelper.CreateBatchAIManager();

                IBatchAICluster cluster = manager.BatchAIClusters.Define(clusterName)
                                          .WithRegion(REGION)
                                          .WithNewResourceGroup(groupName)
                                          .WithVMSize(VirtualMachineSizeTypes.StandardD1V2.Value)
                                          .WithUserName(userName)
                                          .WithPassword("MyPassword")
                                          .WithAutoScale(1, 1)
                                          .WithLowPriority()
                                          .DefineSetupTask()
                                          .WithCommandLine("echo Hello World!")
                                          .WithStdOutErrPath("./outputpath")
                                          .Attach()
                                          .DefineAzureFileShare()
                                          .WithStorageAccountName(saName)
                                          .WithAzureFileUrl(fileShareUri)
                                          .WithRelativeMountPath(shareMountPath)
                                          .WithAccountKey(storageAccountKey)
                                          .Attach()
                                          .DefineAzureBlobFileSystem()
                                          .WithStorageAccountName(saName)
                                          .WithContainerName(containerName)
                                          .WithRelativeMountPath(blobFileSystemPath)
                                          .WithAccountKey(storageAccountKey)
                                          .Attach()
                                          .WithTag("tag1", "value1")
                                          .Create();
                Assert.Equal(AllocationState.Steady, cluster.AllocationState);
                Assert.Equal(userName, cluster.AdminUserName);
                Assert.Equal(VmPriority.Lowpriority, cluster.VMPriority);
                Assert.Equal(1, cluster.NodeSetup.MountVolumes.AzureFileShares.Count);
                Assert.Equal(shareMountPath, cluster.NodeSetup.MountVolumes.AzureFileShares.ElementAt(0).RelativeMountPath);
                Assert.Equal(1, cluster.NodeSetup.MountVolumes.AzureBlobFileSystems.Count);
                Assert.Equal(blobFileSystemPath, cluster.NodeSetup.MountVolumes.AzureBlobFileSystems.ElementAt(0).RelativeMountPath);

                cluster.Update()
                .WithAutoScale(1, 2, 2)
                .WithTag("tag1", "value2")
                .Apply();
                Assert.Equal(2, cluster.ScaleSettings.AutoScale.MaximumNodeCount);
                string tag1;
                Assert.True(cluster.Tags.TryGetValue("tag1", out tag1));
                Assert.Equal("value2", tag1);

                manager.ResourceManager.ResourceGroups.DeleteByName(groupName);
            }
        }
 internal BatchAIJobImpl(string name, BatchAIClusterImpl parent, JobInner inner)
     : base(name, inner, parent.Manager)
 {
     this.parent = parent;
     WithExistingResourceGroup(parent.ResourceGroupName);
 }
 internal BatchAIJobImpl(string name, BatchAIClusterImpl parent, JobInner inner)
     : base(name, inner, parent.Manager)
 {
     this.parent = parent;
 }