当前位置: 首页 > wzjs >正文

php和ASP网站那个好济南新闻头条最新事件

php和ASP网站那个好,济南新闻头条最新事件,呼伦贝尔人才网官方网站入口,个人博客wordpress主题Helsinki-NLP/opus-mt-{en}-{zh}系列翻译模型可以实现200多种语言翻译,Helsinki-NLP/opus-mt-en-zh是其中英互译模型。由于项目需要,在本地进行搭建,并记录下搭建过程,方便后人。 1. 基本硬件环境 CPU:N年前的 Intel…

Helsinki-NLP/opus-mt-{en}-{zh}系列翻译模型可以实现200多种语言翻译,Helsinki-NLP/opus-mt-en-zh是其中英互译模型。由于项目需要,在本地进行搭建,并记录下搭建过程,方便后人。

1. 基本硬件环境

  • CPU:N年前的 Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz, 32G内存
  • GPU:N年前的 NVIDIA GeForce GTX 1080 Ti,11G显存

2. 基本软件环境

  • 操作系统:Ubuntu20.04 LTS,是为了跟老旧的硬件相匹配,专门降级到20.04的,更高版本存在各种软件兼容性问题,等有钱了全部换新!!!
  • CUDA:cuda_12.0.0_525.60.13_linux.run,虽然能支持到12.2甚至12.4,保险起见还是选择了12.0
  • Cudnn:libcudnn8_8.8.0.121-1+cuda12.0_amd64.deb,对应CUDA版本
  • NCCL:libnccl2_2.19.3-1+cuda12.0_amd64.deb对应CUDA版本,多显卡需要
  • miniconda:Miniconda3-py312_24.9.2-0-Linux-x86_64.sh

3. 克隆fishspeech代码并安装本地依赖包

git clone https://gitclone.com/github.com/fishaudio/fish-speech.gitsudo apt-get install ffmpeg libsm6 libxext6 portaudio19-dev -y

4. 创建虚拟环境

conda create -n huggingface python==3.10 -y
conda activate huggingface

5. conda安装基础包

conda install -c pytorch -c nvidia -c conda-forge pytorch torchvision pytorch-cuda=11.8

6. 安装huggingface组件,transformers包

pip install transformers -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install -U huggingface_hub -i https://pypi.tuna.tsinghua.edu.cn/simple设置环境变量,用于加速
HF_ENDPOINT=https://hf-mirror.com

7. 以python脚本方式运行

# Load model directly
from transformers import AutoTokenizer, AutoModelForSeq2SeqLMtokenizer = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-zh")
model = AutoModelForSeq2SeqLM.from_pretrained("Helsinki-NLP/opus-mt-en-zh")def translate(text):inputs = tokenizer(text, return_tensors="pt", padding=True)translated = model.generate(**inputs)return [tokenizer.decode(t, skip_special_tokens=True) for t in translated]print(tokenizer.supported_language_codes)
text = ">>cmn_Hans<< Due to a bug fix in https://github.com/huggingface/transformers/pull/28687 transcription using a multilingual Whisper will default to language detection followed by transcription instead of translation to English.This might be a breaking change for your use case. If you want to instead always translate your audio to English, make sure to pass `language='en'`. The attention mask is not set and cannot be inferred from input because pad token is same as eos token. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results."
translated_text = translate(text)
print(translated_text)

首次运行会报错,因为缺少两个依赖包,安装即可

pip install sentencepiece sacremoses -i https://pypi.tuna.tsinghua.edu.cn/simple

8. 以FastAPI方式运行

# 安装fastapi ubicorn组件
pip install fastapi uvicorn -i https://pypi.tuna.tsinghua.edu.cn/simple

服务脚本如下:

# Load model directly
from fastapi import FastAPI
from pydantic import BaseModel
from transformers import AutoTokenizer, AutoModelForSeq2SeqLMapp = FastAPI()tokenizer = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-zh")
model = AutoModelForSeq2SeqLM.from_pretrained("Helsinki-NLP/opus-mt-en-zh")def translate(text):inputs = tokenizer(text, return_tensors="pt", padding=True)translated = model.generate(**inputs)return [tokenizer.decode(t, skip_special_tokens=True) for t in translated]# print(tokenizer.supported_language_codes)
# text = ">>cmn_Hans<< Due to a bug fix in https://github.com/huggingface/transformers/pull/28687 transcription using a multilingual Whisper will default to language detection followed by transcription instead of translation to English.This might be a breaking change for your use case. If you want to instead always translate your audio to English, make sure to pass `language='en'`. The attention mask is not set and cannot be inferred from input because pad token is same as eos token. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results."
# translated_text = translate(text)
# print(translated_text)class TextRequest(BaseModel):text: str@app.post("/predict")
async def predict(request: TextRequest):# 预处理和预测translated_text = translate(request.text)# 返回结果return {"text": request.text,"predictions": translated_text}

运行服务

uvicorn fastapi_app:app --host 0.0.0.0 --port 8000

http://www.dtcms.com/wzjs/441267.html

相关文章:

  • 美国人做的古文字网站百度竞价排名服务
  • 网站设计方法软文广告是什么
  • 普宁网站建设长春seo优化企业网络跃升
  • 贸易公司做网站有优势吗宁波seo博客
  • 网站点击率多少正常百度下载安装免费下载
  • 微信支付网站未建设完善seo工具有哪些
  • b2c购物网站设计全球搜索引擎排行榜
  • 网站关键词太多网络营销有什么方式
  • 杭州网站建设电话沈阳百度推广排名优化
  • 广州网站建设市场搜索引擎排名优化
  • 手表设计网站sem优化公司
  • 仿冒网站制作h5下一页
  • 网站开发 报价单网络推广文案策划
  • 西宁网站建设官网怎么做网页
  • wordpress注册发邮件贺贵江seo教程
  • cn网站建设多少钱国外黄冈网站推广软件
  • qq头像网站源码低价刷粉网站推广
  • 网站建设页面底部叫什么网站怎么进入
  • 如何网站建设网页宣传推广方案
  • 网站的栏目和板块设计今日热点新闻事件
  • 如何做网站宣传片企业seo排名哪家好
  • 工业设计东莞网站建设石家庄seo推广
  • 响应式网站开发工具长春网站制作设计
  • 湖南北山建设集团网站河南搜索引擎优化
  • 美国设计网站百度云官网首页
  • 小程序开发的服务怎么样灰色行业seo
  • 云指建站平台网上怎么找客户资源
  • 做网站用服务器互联网营销师培训多少钱
  • 网站免费建站o域名seo查询
  • 零基础网站建设视频seo中国官网