azure-mgmt-weightsandbiases-dotnet
microsoft/skills
使用 .NET SDK 在 Azure 上管理“权重与偏置”(W&B)机器学习实验追踪实例。通过市场集成和单点登录(SSO)功能,创建、配置、列出、更新和删除 W&B 实例。
...展开全部Azure.ResourceManager.WeightsAndBiases (.NET)
用于通过 Azure 市场部署和管理 Weights & Biases 机器学习实验跟踪实例的 Azure Resource Manager SDK。
安装
dotnet add package Azure.ResourceManager.WeightsAndBiases --prerelease
dotnet add package Azure.Identity
当前版本:v1.0.0-beta.1(预览版)
API 版本:2024-09-18-preview
环境变量
AZURE_SUBSCRIPTION_ID= # 必填:Azure 订阅 ID
AZURE_RESOURCE_GROUP= # 必填:Azure 资源组名称
AZURE_WANDB_INSTANCE_NAME= # 必填:Weights & Biases 实例名称
AZURE_TOKEN_CREDENTIALS=prod # 仅当在生产环境中使用 DefaultAzureCredential 时才必填
身份验证
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.WeightsAndBiases;
// 本地开发环境:使用 DefaultAzureCredential。生产环境:将 AZURE_TOKEN_CREDENTIALS 设置为 prod 或 AZURE_TOKEN_CREDENTIALS 设置为
var credential = new DefaultAzureCredential(
DefaultAzureCredential.DefaultEnvironmentVariableName
);
// 或者在生产环境中直接使用特定凭据:
// 参见 https://learn.microsoft.com/dotnet/api/overview/azure/identity-readme?view=azure-dotnet#credential-classes
// var credential = new ManagedIdentityCredential();
ArmClient client = new ArmClient(credential);
资源层次结构
订阅
└── 资源组
└── WeightsAndBiasesInstance # 来自 Azure 市场的 W&B 部署
├── Properties
│ ├── Marketplace # 产品详情、套餐、发布者
│ ├── User # 管理员用户信息
│ ├── PartnerProperties # W&B 特定配置(区域、子域)
│ └── SingleSignOnPropertiesV2 # Entra ID 单点登录 (SSO) 配置
└── Identity # 托管身份(可选)
核心工作流
1. 创建 Weights & Biases 实例
using Azure.ResourceManager.WeightsAndBiases;
using Azure.ResourceManager.WeightsAndBiases.Models;
ResourceGroupResource resourceGroup = await client
.GetDefaultSubscriptionAsync()
.Result
.GetResourceGroupAsync("my-resource-group");
WeightsAndBiasesInstanceCollection instances = resourceGroup.GetWeightsAndBiasesInstances();
WeightsAndBiasesInstanceData data = new WeightsAndBiasesInstanceData(AzureLocation.EastUS)
{
Properties = new WeightsAndBiasesInstanceProperties
{
// 市场配置
Marketplace = new WeightsAndBiasesMarketplaceDetails
{
SubscriptionId = "",
OfferDetails = new WeightsAndBiasesOfferDetails
{
PublisherId = "wandb",
OfferId = "wandb-pay-as-you-go",
PlanId = "wandb-payg",
PlanName = "按量付费",
TermId = "monthly",
TermUnit = "P1M"
}
},
// 管理员用户
User = new WeightsAndBiasesUserDetails
{
FirstName = "Admin",
LastName = "User",
EmailAddress = "[email protected]",
Upn = "[email protected]"
},
// W&B 特定配置
PartnerProperties = new WeightsAndBiasesPartnerProperties
{
Region = WeightsAndBiasesRegion.EastUS,
Subdomain = "my-company-wandb"
}
},
// 可选:启用托管身份
Identity = new ManagedServiceIdentity(ManagedServiceIdentityType.SystemAssigned)
};
ArmOperation operation = await instances
.CreateOrUpdateAsync(WaitUntil.Completed, "my-wandb-instance", data);
WeightsAndBiasesInstanceResource 实例 = operation.Value;
Console.WriteLine($"已创建 W&B 实例:{instance.Data.Name}");
Console.WriteLine($"配置状态:{instance.Data.Properties.ProvisioningState}");
2. 获取现有实例
WeightsAndBiasesInstanceResource instance = await resourceGroup
.GetWeightsAndBiasesInstanceAsync("my-wandb-instance");
Console.WriteLine($"实例:{instance.Data.Name}");
Console.WriteLine($"位置:{instance.Data.Location}");
Console.WriteLine($"状态:{instance.Data.Properties.ProvisioningState}");
if (instance.Data.Properties.PartnerProperties != null)
{
Console.WriteLine($"区域: {instance.Data.Properties.PartnerProperties.Region}");
Console.WriteLine($"子域: {instance.Data.Properties.PartnerProperties.Subdomain}");
}
3. 列出所有实例
// 列出资源组中的实例
await foreach (WeightsAndBiasesInstanceResource instance in
resourceGroup.GetWeightsAndBiasesInstances())
{
Console.WriteLine($"实例:{instance.Data.Name}");
Console.WriteLine($" 位置: {instance.Data.Location}");
Console.WriteLine($" 状态: {instance.Data.Properties.ProvisioningState}");
}
// 订阅中的列表
SubscriptionResource 订阅 = await 客户端.GetDefaultSubscriptionAsync();
await foreach (WeightsAndBiasesInstanceResource 实例 in
订阅.GetWeightsAndBiasesInstancesAsync())
{
Console.WriteLine($"{instance.Data.Name} 位于 {instance.Id.ResourceGroupName}");
}
4. 配置单点登录 (SSO)
WeightsAndBiasesInstanceResource instance = await resourceGroup
.GetWeightsAndBiasesInstanceAsync("my-wandb-instance");
// 更新 SSO 配置
WeightsAndBiasesInstanceData updateData = instance.Data;
updateData.Properties.SingleSignOnPropertiesV2 = new WeightsAndBiasSingleSignOnPropertiesV2
{
Type = WeightsAndBiasSingleSignOnType.Saml,
State = WeightsAndBiasSingleSignOnState.Enable,
EnterpriseAppId = "",
AadDomains = { "example.com", "contoso.com" }
};
ArmOperation operation = await resourceGroup
.GetWeightsAndBiasesInstances()
.CreateOrUpdateAsync(WaitUntil.Completed, "my-wandb-instance", updateData);
5. 更新实例
WeightsAndBiasesInstanceResource 实例 = await resourceGroup
.GetWeightsAndBiasesInstanceAsync("my-wandb-instance");
// 更新标签
WeightsAndBiasesInstancePatch 补丁 = new WeightsAndBiasesInstancePatch
{
Tags =
{
{ "environment", "production" },
{ "team", "ml-platform" },
{ "costCenter", "CC-ML-001" }
}
};
instance = await instance.UpdateAsync(patch);
Console.WriteLine($"已更新实例:{instance.Data.Name}");
6. 删除实例
WeightsAndBiasesInstanceResource instance = await resourceGroup
.GetWeightsAndBiasesInstanceAsync("my-wandb-instance");
await instance.DeleteAsync(WaitUntil.Completed);
Console.WriteLine("实例已删除");
7. 检查资源名称可用性
// 创建前检查名称是否可用
// (如果 SDK 未提供此功能,请通过直接调用 ARM 实现)
try
{
await resourceGroup.GetWeightsAndBiasesInstanceAsync("desired-name");
Console.WriteLine("名称已被占用");
}
catch (RequestFailedException ex) when (ex.Status == 404)
{
Console.WriteLine("名称可用");
}
键类型参考
| 类型 | 用途 |
|---|---|
WeightsAndBiasesInstanceResource |
权重和偏置实例资源 |
权重和偏置实例数据 |
实例配置数据 |
权重和偏置实例集合 |
实例集合 |
权重和偏置实例属性 |
实例属性 |
权重和偏置市场详情 |
市场订阅信息 |
权重和偏置报价详情 |
市场报价详情 |
权重和偏置用户详情 |
管理员用户信息 |
WeightsAndBiases 合作伙伴属性 |
W&B 特定配置 |
WeightsAndBias 单点登录属性 V2 |
单点登录配置 |
权重和偏置实例补丁 |
用于更新的补丁 |
权重和偏置区域 |
支持的区域枚举 |
可用区域
| 区域枚举 | Azure 区域 |
|---|---|
WeightsAndBiasesRegion.EastUS |
美国东部 |
WeightsAndBiasesRegion.CentralUS |
美国中部 |
WeightsAndBiasesRegion.WestUS |
美国东部 |
权重和偏差区域.西欧 |
西欧 |
权重与偏差区域.日本东部 |
日本东部 |
权重和偏差区域.韩国中部 |
韩国中部 |
市场平台产品详情
关于 Azure 市场集成:
| 属性 | 值 |
|---|---|
| 发布者 ID | wandb |
| 产品 ID | wandb-按需付费 |
| 套餐 ID | wandb-payg(按量付费) |
最佳实践
- 使用 DefaultAzureCredential— 自动支持多种身份验证方法
- 启用托管身份— 用于安全访问其他 Azure 资源
- 配置单点登录 (SSO)— 启用 Entra ID 单点登录以增强企业安全性
- 为资源添加标签— 使用标签进行成本跟踪和组织管理
- 检查配置状态— 在使用实例前,请等待状态变为
“成功” - 使用合适的区域— 选择距离您的计算资源最近的区域
- 使用 Azure 进行监控— 使用 Azure Monitor 监控资源健康状况
错误处理
using Azure;
try
{
ArmOperation operation = await instances
.CreateOrUpdateAsync(WaitUntil.Completed, "my-wandb", data);
}
catch (RequestFailedException ex) when (ex.Status == 409)
{
Console.WriteLine("实例已存在或名称冲突");
}
catch (RequestFailedException ex) when (ex.Status == 400)
{
Console.WriteLine($"配置无效:{ex.Message}");
}
catch (RequestFailedException ex)
{
Console.WriteLine($"Azure 错误:{ex.Status} - {ex.Message}");
}
与 W&B SDK 的集成
创建 Azure 资源后,请使用 W&B Python SDK 进行实验跟踪:
# 安装:pip install wandb
import wandb
# 使用从 Azure 部署的实例中获取的 W&B API 密钥登录
wandb.login(host="https://my-company-wandb.wandb.ai")
# 初始化一个运行
run = wandb.init(project="my-ml-project")
# 记录指标
wandb.log({"accuracy": 0.95, "loss": 0.05})
# 结束运行
run.finish()
相关 SDK
| SDK | 用途 | 安装 |
|---|---|---|
Azure.ResourceManager.WeightsAndBiases |
权重和偏置实例管理(此 SDK) | dotnet add package Azure.ResourceManager.WeightsAndBiases --prerelease |
Azure.ResourceManager.MachineLearning |
Azure ML 工作区 | dotnet add package Azure.ResourceManager.MachineLearning |
参考链接
| 资源 | URL |
|---|---|
| NuGet 包 | https://www.nuget.org/packages/Azure.ResourceManager.WeightsAndBiases |
| W&B 文档 | https://docs.wandb.ai/ |
| Azure 市场 | https://azuremarketplace.microsoft.com/marketplace/apps/wandb.wandb-pay-as-you-go |
| GitHub 源代码 | https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/weightsandbiases |
---
name: azure-mgmt-weightsandbiases-dotnet
description: Manage Weights & Biases ML experiment tracking instances on Azure using the .NET SDK. Create, configure, list, update, and delete W&B instances with marketplace integration and SSO.
license: MIT
---
# Azure.ResourceManager.WeightsAndBiases (.NET)
Azure Resource Manager SDK for deploying and managing Weights & Biases ML experiment tracking instances via Azure Marketplace.
## Installation
```bash
dotnet add package Azure.ResourceManager.WeightsAndBiases --prerelease
dotnet add package Azure.Identity
```
**Current Version**: v1.0.0-beta.1 (preview)
**API Version**: 2024-09-18-preview
## Environment Variables
```bash
AZURE_SUBSCRIPTION_ID=<your-subscription-id> # Required: Azure subscription ID
AZURE_RESOURCE_GROUP=<your-resource-group> # Required: Azure resource group name
AZURE_WANDB_INSTANCE_NAME=<your-wandb-instance> # Required: Weights & Biases instance name
AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in production
```
## Authentication
```csharp
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.WeightsAndBiases;
// Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>
var credential = new DefaultAzureCredential(
DefaultAzureCredential.DefaultEnvironmentVariableName
);
// Or use a specific credential directly in production:
// See https://learn.microsoft.com/dotnet/api/overview/azure/identity-readme?view=azure-dotnet#credential-classes
// var credential = new ManagedIdentityCredential();
ArmClient client = new ArmClient(credential);
```
## Resource Hierarchy
```
Subscription
└── ResourceGroup
└── WeightsAndBiasesInstance # W&B deployment from Azure Marketplace
├── Properties
│ ├── Marketplace # Offer details, plan, publisher
│ ├── User # Admin user info
│ ├── PartnerProperties # W&B-specific config (region, subdomain)
│ └── SingleSignOnPropertiesV2 # Entra ID SSO configuration
└── Identity # Managed identity (optional)
```
## Core Workflows
### 1. Create Weights & Biases Instance
```csharp
using Azure.ResourceManager.WeightsAndBiases;
using Azure.ResourceManager.WeightsAndBiases.Models;
ResourceGroupResource resourceGroup = await client
.GetDefaultSubscriptionAsync()
.Result
.GetResourceGroupAsync("my-resource-group");
WeightsAndBiasesInstanceCollection instances = resourceGroup.GetWeightsAndBiasesInstances();
WeightsAndBiasesInstanceData data = new WeightsAndBiasesInstanceData(AzureLocation.EastUS)
{
Properties = new WeightsAndBiasesInstanceProperties
{
// Marketplace configuration
Marketplace = new WeightsAndBiasesMarketplaceDetails
{
SubscriptionId = "<marketplace-subscription-id>",
OfferDetails = new WeightsAndBiasesOfferDetails
{
PublisherId = "wandb",
OfferId = "wandb-pay-as-you-go",
PlanId = "wandb-payg",
PlanName = "Pay As You Go",
TermId = "monthly",
TermUnit = "P1M"
}
},
// Admin user
User = new WeightsAndBiasesUserDetails
{
FirstName = "Admin",
LastName = "User",
EmailAddress = "[email protected]",
Upn = "[email protected]"
},
// W&B-specific configuration
PartnerProperties = new WeightsAndBiasesPartnerProperties
{
Region = WeightsAndBiasesRegion.EastUS,
Subdomain = "my-company-wandb"
}
},
// Optional: Enable managed identity
Identity = new ManagedServiceIdentity(ManagedServiceIdentityType.SystemAssigned)
};
ArmOperation<WeightsAndBiasesInstanceResource> operation = await instances
.CreateOrUpdateAsync(WaitUntil.Completed, "my-wandb-instance", data);
WeightsAndBiasesInstanceResource instance = operation.Value;
Console.WriteLine($"W&B Instance created: {instance.Data.Name}");
Console.WriteLine($"Provisioning state: {instance.Data.Properties.ProvisioningState}");
```
### 2. Get Existing Instance
```csharp
WeightsAndBiasesInstanceResource instance = await resourceGroup
.GetWeightsAndBiasesInstanceAsync("my-wandb-instance");
Console.WriteLine($"Instance: {instance.Data.Name}");
Console.WriteLine($"Location: {instance.Data.Location}");
Console.WriteLine($"State: {instance.Data.Properties.ProvisioningState}");
if (instance.Data.Properties.PartnerProperties != null)
{
Console.WriteLine($"Region: {instance.Data.Properties.PartnerProperties.Region}");
Console.WriteLine($"Subdomain: {instance.Data.Properties.PartnerProperties.Subdomain}");
}
```
### 3. List All Instances
```csharp
// List in resource group
await foreach (WeightsAndBiasesInstanceResource instance in
resourceGroup.GetWeightsAndBiasesInstances())
{
Console.WriteLine($"Instance: {instance.Data.Name}");
Console.WriteLine($" Location: {instance.Data.Location}");
Console.WriteLine($" State: {instance.Data.Properties.ProvisioningState}");
}
// List in subscription
SubscriptionResource subscription = await client.GetDefaultSubscriptionAsync();
await foreach (WeightsAndBiasesInstanceResource instance in
subscription.GetWeightsAndBiasesInstancesAsync())
{
Console.WriteLine($"{instance.Data.Name} in {instance.Id.ResourceGroupName}");
}
```
### 4. Configure Single Sign-On (SSO)
```csharp
WeightsAndBiasesInstanceResource instance = await resourceGroup
.GetWeightsAndBiasesInstanceAsync("my-wandb-instance");
// Update with SSO configuration
WeightsAndBiasesInstanceData updateData = instance.Data;
updateData.Properties.SingleSignOnPropertiesV2 = new WeightsAndBiasSingleSignOnPropertiesV2
{
Type = WeightsAndBiasSingleSignOnType.Saml,
State = WeightsAndBiasSingleSignOnState.Enable,
EnterpriseAppId = "<entra-app-id>",
AadDomains = { "example.com", "contoso.com" }
};
ArmOperation<WeightsAndBiasesInstanceResource> operation = await resourceGroup
.GetWeightsAndBiasesInstances()
.CreateOrUpdateAsync(WaitUntil.Completed, "my-wandb-instance", updateData);
```
### 5. Update Instance
```csharp
WeightsAndBiasesInstanceResource instance = await resourceGroup
.GetWeightsAndBiasesInstanceAsync("my-wandb-instance");
// Update tags
WeightsAndBiasesInstancePatch patch = new WeightsAndBiasesInstancePatch
{
Tags =
{
{ "environment", "production" },
{ "team", "ml-platform" },
{ "costCenter", "CC-ML-001" }
}
};
instance = await instance.UpdateAsync(patch);
Console.WriteLine($"Updated instance: {instance.Data.Name}");
```
### 6. Delete Instance
```csharp
WeightsAndBiasesInstanceResource instance = await resourceGroup
.GetWeightsAndBiasesInstanceAsync("my-wandb-instance");
await instance.DeleteAsync(WaitUntil.Completed);
Console.WriteLine("Instance deleted");
```
### 7. Check Resource Name Availability
```csharp
// Check if name is available before creating
// (Implement via direct ARM call if SDK doesn't expose this)
try
{
await resourceGroup.GetWeightsAndBiasesInstanceAsync("desired-name");
Console.WriteLine("Name is already taken");
}
catch (RequestFailedException ex) when (ex.Status == 404)
{
Console.WriteLine("Name is available");
}
```
## Key Types Reference
| Type | Purpose |
|------|---------|
| `WeightsAndBiasesInstanceResource` | W&B instance resource |
| `WeightsAndBiasesInstanceData` | Instance configuration data |
| `WeightsAndBiasesInstanceCollection` | Collection of instances |
| `WeightsAndBiasesInstanceProperties` | Instance properties |
| `WeightsAndBiasesMarketplaceDetails` | Marketplace subscription info |
| `WeightsAndBiasesOfferDetails` | Marketplace offer details |
| `WeightsAndBiasesUserDetails` | Admin user information |
| `WeightsAndBiasesPartnerProperties` | W&B-specific configuration |
| `WeightsAndBiasSingleSignOnPropertiesV2` | SSO configuration |
| `WeightsAndBiasesInstancePatch` | Patch for updates |
| `WeightsAndBiasesRegion` | Supported regions enum |
## Available Regions
| Region Enum | Azure Region |
|-------------|--------------|
| `WeightsAndBiasesRegion.EastUS` | East US |
| `WeightsAndBiasesRegion.CentralUS` | Central US |
| `WeightsAndBiasesRegion.WestUS` | West US |
| `WeightsAndBiasesRegion.WestEurope` | West Europe |
| `WeightsAndBiasesRegion.JapanEast` | Japan East |
| `WeightsAndBiasesRegion.KoreaCentral` | Korea Central |
## Marketplace Offer Details
For Azure Marketplace integration:
| Property | Value |
|----------|-------|
| Publisher ID | `wandb` |
| Offer ID | `wandb-pay-as-you-go` |
| Plan ID | `wandb-payg` (Pay As You Go) |
## Best Practices
1. **Use DefaultAzureCredential** — Supports multiple auth methods automatically
2. **Enable managed identity** — For secure access to other Azure resources
3. **Configure SSO** — Enable Entra ID SSO for enterprise security
4. **Tag resources** — Use tags for cost tracking and organization
5. **Check provisioning state** — Wait for `Succeeded` before using instance
6. **Use appropriate region** — Choose region closest to your compute
7. **Monitor with Azure** — Use Azure Monitor for resource health
## Error Handling
```csharp
using Azure;
try
{
ArmOperation<WeightsAndBiasesInstanceResource> operation = await instances
.CreateOrUpdateAsync(WaitUntil.Completed, "my-wandb", data);
}
catch (RequestFailedException ex) when (ex.Status == 409)
{
Console.WriteLine("Instance already exists or name conflict");
}
catch (RequestFailedException ex) when (ex.Status == 400)
{
Console.WriteLine($"Invalid configuration: {ex.Message}");
}
catch (RequestFailedException ex)
{
Console.WriteLine($"Azure error: {ex.Status} - {ex.Message}");
}
```
## Integration with W&B SDK
After creating the Azure resource, use the W&B Python SDK for experiment tracking:
```python
# Install: pip install wandb
import wandb
# Login with your W&B API key from the Azure-deployed instance
wandb.login(host="https://my-company-wandb.wandb.ai")
# Initialize a run
run = wandb.init(project="my-ml-project")
# Log metrics
wandb.log({"accuracy": 0.95, "loss": 0.05})
# Finish run
run.finish()
```
## Related SDKs
| SDK | Purpose | Install |
|-----|---------|---------|
| `Azure.ResourceManager.WeightsAndBiases` | W&B instance management (this SDK) | `dotnet add package Azure.ResourceManager.WeightsAndBiases --prerelease` |
| `Azure.ResourceManager.MachineLearning` | Azure ML workspaces | `dotnet add package Azure.ResourceManager.MachineLearning` |
## Reference Links
| Resource | URL |
|----------|-----|
| NuGet Package | https://www.nuget.org/packages/Azure.ResourceManager.WeightsAndBiases |
| W&B Documentation | https://docs.wandb.ai/ |
| Azure Marketplace | https://azuremarketplace.microsoft.com/marketplace/apps/wandb.wandb-pay-as-you-go |
| GitHub Source | https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/weightsandbiases |
所有文件
0 个文件安装 azure-mgmt-weightsandbiases-dotnet
下载技能文件,并将其解压到 .claude/skills/ 目录中。
下载ZIP克隆仓库并复制技能文件到您的项目中。
git clone https://github.com/microsoft/skills/tree/main/.github/plugins/azure-sdk-dotnet/skills/azure-mgmt-weightsandbiases-dotnet # Copy SKILL.md to your .claude/skills/ directory
复制





首页
