in sdk/dotnet/AzureML-Samples-CSharp/Endpoints/Online/ManagedOnlineEndpointOperations.cs [98:205]
public static async Task<MachineLearningOnlineDeploymentResource> GetOrCreateOnlineDeploymentAsync(
ResourceGroupResource resourceGroup,
string workspaceName,
string endpointName,
string deploymentName,
string modelId,
string environmentId,
string codeArtifactId,
string location)
{
Console.WriteLine("Creating a OnlineDeployment...");
MachineLearningWorkspaceResource ws = await resourceGroup.GetMachineLearningWorkspaces().GetAsync(workspaceName);
MachineLearningOnlineEndpointResource endpointResource = await ws.GetMachineLearningOnlineEndpoints().GetAsync(endpointName);
Console.WriteLine(endpointResource.Data.Id);
bool exists = await endpointResource.GetMachineLearningOnlineDeployments().ExistsAsync(deploymentName);
// https://docs.microsoft.com/azure/machine-learning/how-to-troubleshoot-online-endpoints
MachineLearningOnlineDeploymentResource deploymentResource;
if (exists)
{
Console.WriteLine($"OnlineDeployment {deploymentName} exists.");
deploymentResource = await endpointResource.GetMachineLearningOnlineDeployments().GetAsync(deploymentName);
Console.WriteLine($"OnlineDeploymentResource details: {deploymentResource.Data.Id}");
}
else
{
Console.WriteLine($"OnlineDeployment {deploymentName} does not exist.");
// scaleSettings for Kubernetes
//var scaleSettings = new TargetUtilizationScaleSettings
//{
// PollingInterval = TimeSpan.FromSeconds(1),
// TargetUtilizationPercentage = 50,
// MinInstances = 1,
// MaxInstances = 1,
//};
//scaleSettings = new DefaultScaleSettings();
var managedOnlineDeploymentDetails = new MachineLearningManagedOnlineDeployment
{
Description = "This is a test online deployment",
// EgressPublicNetworkAccess=EgressPublicNetworkAccessType.Disabled,
// The path to mount the model in custom container.
// Custom model mount path for curated environments is not supported
// ModelMountPath = "/var/mountpath",
EgressPublicNetworkAccess = MachineLearningEgressPublicNetworkAccessType.Disabled,
Properties = { { "additionalProp1", "value1" } },
EnvironmentId = environmentId,
EnvironmentVariables = new Dictionary<string, string>
{
{ "TestVariable", "TestValue" }
},
RequestSettings = new MachineLearningOnlineRequestSettings
{
MaxQueueWait = TimeSpan.FromMilliseconds(30),
RequestTimeout = TimeSpan.FromMilliseconds(60),
MaxConcurrentRequestsPerInstance = 3,
},
LivenessProbe = new MachineLearningProbeSettings
{
FailureThreshold = 10,
SuccessThreshold = 1,
InitialDelay = TimeSpan.FromSeconds(10),
Timeout = TimeSpan.FromSeconds(10),
Period = TimeSpan.FromSeconds(2),
},
// Only for ManagedOnlineDeployment
ReadinessProbe = new MachineLearningProbeSettings
{
FailureThreshold = 10,
SuccessThreshold = 1,
InitialDelay = TimeSpan.FromSeconds(10),
Timeout = TimeSpan.FromSeconds(10),
Period = TimeSpan.FromSeconds(2),
},
AppInsightsEnabled = false,
CodeConfiguration = new MachineLearningCodeConfiguration("main.py")
{
CodeId = new ResourceIdentifier(codeArtifactId),
},
InstanceType = "Standard_F2s_v2",
Model = modelId,
// ScaleSettings = new DefaultScaleSettings(),
};
MachineLearningOnlineDeploymentData data = new MachineLearningOnlineDeploymentData(location, managedOnlineDeploymentDetails)
{
Kind = "SampleKindDeployment",
Sku = new MachineLearningSku("Default")
{
Tier = MachineLearningSkuTier.Standard,
Capacity = 2,
Family = "familyA",
Size = "Standard_F2s_v2",
},
};
ArmOperation<MachineLearningOnlineDeploymentResource> deploymentResourceOperation = await endpointResource.GetMachineLearningOnlineDeployments().CreateOrUpdateAsync(WaitUntil.Completed, deploymentName, data);
deploymentResource = deploymentResourceOperation.Value;
Console.WriteLine($"OnlineDeploymentResource {deploymentResource.Data.Id} created.");
}
return deploymentResource;
}