
MuselandAI替代方案与AI工具在求职中的应用
在使用国家超算互联网平台时,我首先对异构加速卡AI进行了性能测试。为了准确评估其性能,我使用了ResNet网络进行训练测试。下方是我使用的代码块:
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' # Only show error messages
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}')
测试结果显示,异构加速卡AI的性能与L20显卡相当,甚至在显存和价格上有一定优势。通过这个测试,我确认异构加速卡AI能够满足大多数深度学习任务的需求。
在完成ResNet网络的测试后,我对异构加速卡AI进行了Llama3模型的推理测试。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() # 结束计时
# 计算生成的 token 数
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能够流畅地运行Llama3模型,得益于其64GB的显存支持。模型推理速度也非常令人满意。
由于异构加速卡AI的兼容性良好,我决定使用PEFT框架对Llama3进行微调,以测试其在个性化语言模型方面的能力。微调的目标是让模型能以《甄嬛传》的语气回答问题。
为了进行微调,我首先准备了《甄嬛传》中的角色对话数据,并将其存储为JSON格式。以下是数据的示例:
接下来,我加载了模型和分词器,并使用Pandas库加载了JSON数据集。通过定义函数将对话数据编码并存储在变量中,以便训练时调用。
在微调过程中,我选择对语言风格影响较大的模块进行LoRA训练,以控制语言风格。训练过程非常顺利,异构加速卡AI的兼容性得到了充分验证。
SCNet平台提供的数据集和模型商城是我最为欣赏的功能之一。例如,在平台上下载COCO2017数据集只需几分钟时间,这得益于其内网传输的高效性。在开发过程中,这种便利性极大地提升了我的工作效率。
开发者可以选择多种环境来进行开发,这减少了部署环境的困难,使得时间得以更有效的利用。异构加速卡AI完全支持Pytorch在日常开发中的使用,并提供了与L20相当的算力和更大显存,价格也更加亲民。
异构加速卡AI采用了新一代国产AI加速卡技术,基于通用GPGPU架构设计,能够对标NVIDIA的产品,具有应用生态完善、迁移成本低的特点。其兼容性非常好,可以轻松部署和运行主流的开源大模型。
在实际应用中,异构加速卡AI以其高性价比赢得了很多开发者的喜爱,无需转码即可直接使用基于PyTorch、TensorFlow等主流框架实现的代码。
LLaVA模型是一个视觉指令微调模型,结构简单但功能强大。它由CLIP视觉编码器、Vicuna大语言模型和一个Projection层组成。视觉编码器负责将输入图像转换为视觉特征向量,Projection层则将视觉特征转换为语义特征空间,与语言模型对齐。
在LLaVA模型的训练过程中,参数冻结技术的应用是其一大亮点。这种技术通过在训练过程中冻结某些层的参数,减少了显存的占用,提升了训练效率。
LLaVA模型的训练分为两个阶段。第一阶段是预训练,冻结视觉编码器与大语言模型的参数,仅训练Projection层,以实现图像特征与大模型的对齐。第二阶段则是视觉指令微调,更新大语言模型和Projection层的参数。
在微调过程中,我尝试了LoRA微调方法。这种方法通过将可训练的低秩分解矩阵注入到Transformer架构中,大大减少了可训练参数量,提高了微调效率。
答:异构加速卡AI是一种基于通用GPGPU架构设计的新一代国产AI加速卡,具有高性价比和良好的兼容性。
答:SCNet平台提供了多种计算资源和环境选择,开发者可以根据项目需求选择合适的资源和环境进行优化。
答:视觉指令微调是一种在指令中嵌入图像数据的微调方法,旨在让模型能够更好地理解和遵循视觉指令。
答:LoRA微调方法的核心是通过低秩分解减少在下游任务上的可训练参数量,从而提高微调效率。
答:SCNet平台的模型和数据集商城提供了丰富的资源,开发者可以快速下载并应用到项目中,极大地节省时间和精力。
通过以上测试和体验,我对国家超算互联网平台的高效性和便利性有了深刻的认识。无论是异构加速卡AI的优越性能,还是SCNet平台的便利性,都为AI开发者提供了强有力的支持。