"modelscope中, 为啥不使用gpu,只使用cpu?
def t2t_generator_result(input_filepath, output_filepath):
os.makedirs(INPUT_DIR, exist_ok=True) # noqa: F405
os.makedirs(OUTPUT_DIR, exist_ok=True) # noqa: F405
task = Tasks.text2text_generation
# model = r""damo/nlp_mt5_zero-shot-augment_chinese-base""
model = os.path.join(MODEL_DIR, ModelFile.TRAIN_OUTPUT_DIR) # noqa: F405
if torch.cuda.is_available():
device = ""cuda""
print(""CUDA is available. You can use GPU."")
else:
device = ""cpu""
print(""CUDA is not available. You can only use CPU."")
pipeline_ins = pipeline(task=task, model=model,device=""gpu"")
df = pd.read_csv(input_filepath, encoding=""utf-8"")
labels = ""城中村,居民小区,聚类市场,农村非住宅,农村住宅,企事业单位,商务楼宇,沿街商铺""
outputs = []
for index, row in tqdm(
df.iterrows(),
total=len(df),
desc=""Processing"",
bar_format=""{l_bar}{bar} | {n_fmt}/{total_fmt} [{elapsed}<{remaining}]"",
):
output = {}
full_name = row[""full_name""]
first_label = row[""first_lable""]
text_str = f""文本分类。\n候选标签:{labels}\n文本内容:{full_name}""
result = pipeline_ins(text_str)
print(result)
output[""full_name""] = full_name
output[""first_lable""] = first_label
output[""new_labels""] = result
outputs.append(output)
matched_df = pd.DataFrame(outputs)
matched_df.to_csv(output_filepath, index=False, encoding=""utf-8"")"
ModelScope旨在打造下一代开源的模型即服务共享平台,为泛AI开发者提供灵活、易用、低成本的一站式模型服务产品,让模型应用更简单!欢迎加入技术交流群:微信公众号:魔搭ModelScope社区,钉钉群号:44837352