【发布时间】:2022-01-12 01:53:12
【问题描述】:
我正在关注谷歌云上的顶点AI教程,基于colab(文本分类):
特别是我想了解如何在 GCP(谷歌云平台)上使用在 vertex-ai 中训练的模型进行数千次预测。
我认为本教程中关于该主题的有趣部分是“从您的模型中获取批量预测”部分。然而,他们展示了一种方法,该方法涉及生成一堆文件,每个文本一个文件,并将所有文件保存在谷歌云存储的存储桶中。这些是完成此操作的笔记本上的行:
instances = [
"We hiked through the woods and up the hill to the ice caves",
"My kitten is so cute",
]
input_file_name = "batch-prediction-input.jsonl"
...
# Instantiate the Storage client and create the new bucket
storage = storage.Client()
bucket = storage.bucket(BUCKET_NAME)
# Iterate over the prediction instances, creating a new TXT file
# for each.
input_file_data = []
for count, instance in enumerate(instances):
instance_name = f"input_{count}.txt"
instance_file_uri = f"{BUCKET_URI}/{instance_name}"
# Add the data to store in the JSONL input file.
tmp_data = {"content": instance_file_uri, "mimeType": "text/plain"}
input_file_data.append(tmp_data)
# Create the new instance file
blob = bucket.blob(instance_name)
blob.upload_from_string(instance)
input_str = "\n".join([str(d) for d in input_file_data])
file_blob = bucket.blob(f"{input_file_name}")
file_blob.upload_from_string(input_str)
...
然后他们加载模型并创建一个作业:
job_display_name = "e2e-text-classification-batch-prediction-job"
model = aiplatform.Model(model_name=model_name)
batch_prediction_job = model.batch_predict(
job_display_name=job_display_name,
gcs_source=f"{BUCKET_URI}/{input_file_name}",
gcs_destination_prefix=f"{BUCKET_URI}/output",
sync=True,
)
我的问题是这样的。真的有必要为每个句子生成一个文件吗?如果我们有数千个文本,这涉及在 GCP 上生成和保存数千个小文件。这不会损害性能吗?此外,该模型是否仍然能够像通常的 Tensorflow 模型一样利用矢量化来“批量”处理输入?
【问题讨论】:
标签: python-3.x google-cloud-platform google-cloud-storage