所有文章 > 日积月累 > 国家超算互联网平台:探索未来的AI算力
国家超算互联网平台:探索未来的AI算力

国家超算互联网平台:探索未来的AI算力

国家超算互联网平台的简介

国家超算互联网平台由国家部委支持并指导,是一个集超算算力、网络、服务、资源共享于一体的综合性平台。平台的目标是连接全国的超算资源,为企业和科研机构提供高效的算力支持。目前,平台已吸引了超过200家专业服务商入驻,并上架了6000多款商品,包括基础算力资源、应用软件、数据和模型等多种类型。

异构加速卡AI与L20的对比测试

在国家超算互联网平台上,异构加速卡AI是一个非常引人注目的产品。相比于L20,加速卡AI提供了更大的显存和更低的价格,这吸引了大量用户进行测试和使用。为了评估其性能,我使用了ResNet网络进行了性能测试。

ResNet网络性能测试

如下是ResNet网络的测试代码,其中利用了TensorFlow框架来评估加速卡的训练性能。

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'

import tensorflow as tf
from tensorflow.keras import layers, models

gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
    try:
        for gpu in gpus:
            tf.config.experimental.set_memory_growth(gpu, True)
    except RuntimeError as e:
        print(e)

(x_train, y_train), (x_test, y_test) = tf.keras.datasets.cifar100.load_data()

x_train, x_test = x_train / 255.0, x_test / 255.0

def resnet_block(inputs, num_filters, kernel_size=3, strides=1, activation='relu'):
    x = layers.Conv2D(num_filters, kernel_size=kernel_size, strides=strides, padding='same')(inputs)
    x = layers.BatchNormalization()(x)
    if activation:
        x = layers.Activation(activation)(x)
    return x

def resnet_identity_block(inputs, num_filters):
    x = resnet_block(inputs, num_filters)
    x = resnet_block(x, num_filters, activation=None)
    x = layers.Add()([x, inputs])
    x = layers.Activation('relu')(x)
    return x

def resnet_conv_block(inputs, num_filters, strides=2):
    x = resnet_block(inputs, num_filters, strides=strides)
    x = resnet_block(x, num_filters, activation=None)
    shortcut = layers.Conv2D(num_filters, kernel_size=1, strides=strides, padding='same')(inputs)
    shortcut = layers.BatchNormalization()(shortcut)
    x = layers.Add()([x, shortcut])
    x = layers.Activation('relu')(x)
    return x

def build_resnet(input_shape, num_classes):
    inputs = layers.Input(shape=input_shape)
    x = resnet_block(inputs, 64)
    x = resnet_conv_block(x, 128)
    x = resnet_identity_block(x, 128)
    x = resnet_conv_block(x, 256)
    x = resnet_identity_block(x, 256)
    x = resnet_conv_block(x, 512)
    x = resnet_identity_block(x, 512)
    x = layers.GlobalAveragePooling2D()(x)
    outputs = layers.Dense(num_classes, activation='softmax')(x)
    model = models.Model(inputs, outputs)
    return model

input_shape = (32, 32, 3)
num_classes = 100
model = build_resnet(input_shape, num_classes)

model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])

history = model.fit(x_train,
                    y_train,
                    epochs=10,
                    validation_data=(x_test, y_test),
                    batch_size=4*74)

test_loss, test_acc = model.evaluate(x_test, y_test, verbose=2)
print(f'Test accuracy: {test_acc}')

图一:L20在训练的第一轮大概10秒

通过这个小测试,我认为异构加速卡AI的性能和L20是相差无几的。

Llama3推理测试

在完成ResNet网络测试后,我继续在异构加速卡AI上进行了Llama3模型的推理测试。这个模型是在平台的商城下载的,下载速度非常快。

使用以下代码进行推理测试:

from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
import time

model_path = "/root/private_data/Llama3-8B-Chinese-Chat"

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
if torch.cuda.is_available():
    print("模型在异构加速卡上运行")
else:
    print("模型在CPU上运行")

tokenizer = AutoTokenizer.from_pretrained(model_path)

model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=torch.float32).to(device)

def generate_response(prompt):
    inputs = tokenizer(prompt, return_tensors="pt").to(device)
    start_time = time.time()
    outputs = model.generate(
        inputs["input_ids"],
        max_length=512,
        num_beams=5,
        no_repeat_ngram_size=2,
        early_stopping=True,
        top_k=50,
        top_p=0.95,
        temperature=0.7
    )
    end_time = time.time()

    generated_tokens = outputs.size(1)
    generation_time = end_time - start_time

    response = tokenizer.decode(outputs[0], skip_special_tokens=True)
    tokens_per_second = generated_tokens / generation_time

    return response, tokens_per_second

prompts = ["你好, 你可以介绍一下你自己吗?"]
for prompt in prompts:
    response, tokens_per_second = generate_response(prompt)
    print(f"模型输出: {response}")
    print(f"生成速度是: {tokens_per_second:.2f} tk/s")

运行效果证明,异构加速卡AI凭借其64GB显存,在FP32精度下运行毫无压力。

使用PEFT框架对Llama3进行微调

异构加速卡AI虽然有64GB显存,但其兼容性是一个值得关注的问题。在此,我使用PEFT框架对Llama3-8B-Chinese-Chat进行了微调,目标是打造一个能够使用《甄嬛传》风格回答问题的模型。

微调过程非常顺利,异构加速卡AI对PyTorch的兼容性表现出色,没有出现任何兼容性问题。

平台的多样化选择

国家超算互联网平台不仅提供丰富的算力资源,还提供了多种开发环境选择,极大地方便了用户的开发工作。通过使用平台的内置数据集商城和模型商城,用户可以快速下载所需的数据和模型,加速开发过程。

总结与体验

国家超算互联网平台在提供算力资源的同时,还为用户提供了丰富的开发工具和便捷的资源获取途径。异构加速卡AI在PyTorch上的兼容性和性能表现也令人满意,为用户的AI项目开发提供了可靠的硬件支持。

FAQ

  1. 问:异构加速卡AI与L20相比有什么优势?

    • 答:异构加速卡AI提供了更大的显存和更低的价格,在性能上与L20相差无几。
  2. 问:如何在国家超算互联网平台上下载模型?

    • 答:在平台的商城中可以快速下载模型,下载速度快于公网下载。
  3. 问:异构加速卡AI对PyTorch的兼容性如何?

    • 答:在使用过程中,异构加速卡AI对PyTorch表现出良好的兼容性,未出现兼容性问题。
  4. 问:平台提供哪些开发环境选择?

    • 答:平台提供了多种开发环境选择,用户可以根据项目需求选择合适的环境。
  5. 问:如何参与平台的算力赠送活动?

    • 答:用户可以注册平台账号,并按照活动规则进行开发和提交成果,即可获得算力赠送。
#你可能也喜欢这些API文章!