Skip to main content

Onebrain-SDK

安装

首先镜像里需安装onebrain-sdk。可以采用whl包本地安装的形式。 一般来说,平台提供的镜像里应该已经集成onebrain-sdk了。

打最新的whl包

git clone https://gitee.com/onebrain/onebrain-sdk.git
python setup.py bdist_wheel -d onebrain

将whl包上传至镜像

安装whl包

pip install onebrain-0.0.1-py3-none-any.whl

SDK说明 使用示例

from onebrain.api import OnebrainClient

run_id = "my_train_job"
# 创建与平台通信的client对象
client = OnebrainClient()

然后就可以通过client对象来上传指标到平台了 以pytorch训练任务为例

# ...
def train(dataloader:DataLoader, model:nn.Module, loss_fn, optimizer:torch.optim.Optimizer, step):
    image_size = len(dataloader.dataset)
    print(f"数据集的图片总数: {image_size}")

    for batch, (x_train, y_train) in enumerate(dataloader):
        x_train, y_train = x_train.to(device), y_train.to(device)
        y_hat = model(x_train)
        loss = loss_fn(y_hat, y_train)
        loss.backward()
        optimizer.step()
        optimizer.zero_grad()

        if batch % 100 == 0:
            loss, current = loss.item(), batch * len(x)
            print(f'batch:{batch}, loss: {loss}, , image_num:{current}/{image_size}')
            # 上传指标
            client.log_metric(key="loss", value=loss, step=step)

for epoch in range(epochs):
    print(f"Epoch {epoch}\n --------------------------------")
    train(train_dataloader, model, loss_fn, optimizer, epoch)

log_metric方法参数说明:

  • run_id: 训练任务的唯一标识,默认从环境变量获取,填充为平台生成的resourceId
  • key:指标名称
  • value: 指标值
  • timestamp: 时间戳,默认为当前时间
  • step: 训练的step

备注:

在OnebrainClient对象实例化之初,会根据容器的环境变量判断该以何种方式上报平台。 默认为RestfulApi,也支持使用MQ上报指标。当环境变量不存在时,实例化会失败并报错。

Metadata

Release files for onebrain 0.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for onebrain 0.0.9
File Size Uploaded
onebrain-0.0.9.tar.gz 13.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for onebrain 0.0.9
File Interpreter ABI Platform
onebrain-0.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 31.2 kB

Release files / onebrain-0.0.9.tar.gz

Download URL onebrain-0.0.9.tar.gz
Size 13.5 kB
Tags Source
SHA-256 checksum
How to use checksums
340c043963ab2de198ad805b4a03910f79cefeb7cfef807a614be7b864acbcba
BLAKE2b-256 checksum
How to use checksums
7fd25fbb79e736d2724fcf2c71a3dbdcf9891de98ce5f86cd89412f4c4a3f91d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.8

Release files / onebrain-0.0.9-py3-none-any.whl

Download URL onebrain-0.0.9-py3-none-any.whl
Size 17.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b75bd7289782b38163972702e627f285a370bec4fc593ec6baa4fd3d2608431
BLAKE2b-256 checksum
How to use checksums
7cedbb53df0f8e1759a3b6d92d4213148c493807dc94c9c3e678e9b7b9c80319
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.8

Release history Release notifications | RSS feed

This release

0.0.9 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page