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

网站设计时间建设企业网站多少钱

网站设计时间,建设企业网站多少钱,dw动态网站怎么做搜索框,wordpress好用的博客主题本地效果:(如果想做这个的本科毕设,建议美化界面。) 总结:MobaXterm远程连接autodl服务器,在MobaXterm上利用X11转发使pyqt可视化页面在自己的电脑上展现出来。 1. 官网下载MobaXterm MobaXterm free Xse…

本地效果:(如果想做这个的本科毕设,建议美化界面。)

总结:MobaXterm远程连接autodl服务器,在MobaXterm上利用X11转发使pyqt可视化页面在自己的电脑上展现出来。

1. 官网下载MobaXterm

MobaXterm free Xserver and tabbed SSH client for Windows,我认为这个比pycharm专业版连接autodl服务器更加好用。pycharm需要考虑同步,MobaXterm不需要点那么多同步设置。在MobaXterm上操作也比autodl上的jupyterlab好操作。

2. 在autodl上租服务器

一般一个小时1.6-2r。这里注意显存大小能否支撑起模型的参数量(关于这个具体是怎么判断的,我还不会,会了再补充)我租的是4090D,建议起个早租卡,现在是晚上八点,我刚才创建新的实例租卡租不了,但是早上八点我看有富余。

镜像可以选择社区镜像,我用的是V3版本,它自带了1.5B的模型。deepseek-ai/DeepSeek-R1/DeepSeek-R1: 【一键聊天,多维研究】 DeepSeek-R1,目前位居全球大模型竞技榜前三,性能对标OpenAIo1正式版。深度求索(DeepSeek)公司在2025年1月20日发布的最新模型! - CG

3. MobaXterm连接autodl服务器

【MobaXterm】登录与连接服务器教程_mobaxterm怎么连接服务器-CSDN博客

4. 我下载了7B的模型,注意下面下载到autodl-tmp目录中。

conda activate torch_env
export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download deepseek-ai/DeepSeek-R1-Distill-Qwen-7B --local-dir /root/autodl-tmp/DeepSeek-R1-Distill-Qwen-7B --resume-download

7B模型运行相比1.5那个应该只改了模型路径,运行后可以在终端与模型对话,输入exit退出:

文件名:deepseek_multichat-7B.py 

终端运行输入:python deepseek_multichat-7B.py

import os
import json
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
import unicodedata
from typing import List@torch.inference_mode()
def generate(model: AutoModelForCausalLM,input_ids: torch.Tensor,attention_mask: torch.Tensor,max_new_tokens: int,temperature: float = 1.0
) -> List[int]:"""Generate response from the model with attention_mask provided."""outputs = model.generate(input_ids=input_ids,attention_mask=attention_mask,  # 提供显式 attention maskmax_new_tokens=max_new_tokens,temperature=temperature,eos_token_id=model.config.eos_token_id,pad_token_id=model.config.eos_token_id,do_sample=True,top_k=50,top_p=0.95,)return outputs[0].tolist()def clean_input(user_input):"""清理用户输入,去除不可见字符和多余的空格。"""user_input = "".join(c for c in user_input if not unicodedata.category(c).startswith("C"))  # 移除控制字符return user_input.strip()  # 去除首尾空格def clean_message_content(content):"""清理消息内容,去除首尾空格并过滤非法输入"""if not content or not isinstance(content, str):return ""return content.strip()  # 去除首尾空格def build_prompt(messages, max_history=3):"""Build prompt for the model, limiting the history to the most recent messages."""template = "The following is a conversation with an AI assistant. The assistant is helpful, knowledgeable, and polite:\n"for msg in messages[-max_history:]:content = clean_message_content(msg["content"])if not content:  # 跳过空内容continuetemplate += f"{msg['role'].capitalize()}: {content}\n"template += "Assistant: "return template.strip()  # 确保返回值是字符串if __name__ == "__main__":print("Initializing DeepSeek-R1 Service...")# Configurationckpt_path = "/root/autodl-tmp/DeepSeek-R1-Distill-Qwen-7B"  # 模型所在的目录config_path = "/root/autodl-tmp/DeepSeek-R1-Distill-Qwen-7B/config.json"  # 配置文件路径# Load tokenizer and modeltokenizer = AutoTokenizer.from_pretrained(ckpt_path) model = AutoModelForCausalLM.from_pretrained(ckpt_path,torch_dtype=torch.bfloat16,).cuda()# Interactive sessionmessages = []  # To maintain contextwhile True:user_input = input("You: ").strip()  # 去除首尾空格user_input = clean_input(user_input)  # 清理不可见字符if not user_input or len(user_input.strip()) == 0:  # 检查无效输入print("Invalid input. Please type something meaningful!")continueif user_input.lower() in ["exit", "quit"]:print("Exiting conversation. Goodbye!")break# Append user input to contextmessages.append({"role": "user", "content": user_input})# Limit conversation historymessages = messages[-10:]  # 只保留最近 10 条对话# Build prompt and tokenizeprompt = build_prompt(messages)if not isinstance(prompt, str) or len(prompt.strip()) == 0:  # 确保 prompt 非空print("Error: Prompt is empty or invalid. Skipping this turn.")continuetokenized_prompt = tokenizer(prompt, return_tensors="pt", truncation=True, padding=True)input_ids = tokenized_prompt["input_ids"].to("cuda")attention_mask = tokenized_prompt["attention_mask"].to("cuda")# Generate responsemax_new_tokens = 500 #150temperature = 0.7completion_tokens = generate(model, input_ids, attention_mask, max_new_tokens, temperature)completion = tokenizer.decode(completion_tokens[len(input_ids[0]):],  # 从输入长度截取生成部分skip_special_tokens=True).split("User:")[0].strip()print(f"Assistant: {completion}")# Append assistant response to contextmessages.append({"role": "assistant", "content": completion})

5. 接下来是最让我头疼的pyqt图形化页面显示。

autodl上是不能直接运行出图形化页面的。可以解决有两种方式:第一种方法:模型利用flask打包成api接口,然后在自己电脑上访问这个接口,在自己电脑上显示出来图形化页面;第二种方法:利用X11转发功能,在autodl上运行图形化页面程序,然后在自己电脑上显示。我用的第二种方法,第一种方法是问了师兄,这个还没尝试,之后尝试了再记录。

一开始用Xlaunch不行,MobaXterm就不需要那么多配置。

如果X11 Forward 显示红叉 可以参考:MobaXterm连接服务器,通过x11 Forwarding实现图形可视化(记录个人学习过程)_mobaxterm x11-CSDN博客

最重要的应该是那个X11UseLocalhost no,我用的pyqt,不需要localhost,也设置了no

pyqt页面代码:

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import os
import json
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
import unicodedata
from typing import List# 原模型相关代码保持不变
# [此处插入原文件中的模型加载和生成相关函数,保持原样]@torch.inference_mode()
def generate(model: AutoModelForCausalLM,input_ids: torch.Tensor,attention_mask: torch.Tensor,max_new_tokens: int,temperature: float = 1.0
) -> List[int]:"""Generate response from the model with attention_mask provided."""outputs = model.generate(input_ids=input_ids,attention_mask=attention_mask,  # 提供显式 attention maskmax_new_tokens=max_new_tokens,temperature=temperature,eos_token_id=model.config.eos_token_id,pad_token_id=model.config.eos_token_id,do_sample=True,top_k=50,top_p=0.95,)return outputs[0].tolist()def clean_input(user_input):"""清理用户输入,去除不可见字符和多余的空格。"""user_input = "".join(c for c in user_input if not unicodedata.category(c).startswith("C"))  # 移除控制字符return user_input.strip()  # 去除首尾空格def clean_message_content(content):"""清理消息内容,去除首尾空格并过滤非法输入"""if not content or not isinstance(content, str):return ""return content.strip()  # 去除首尾空格def build_prompt(messages, max_history=3):"""Build prompt for the model, limiting the history to the most recent messages."""template = "The following is a conversation with an AI assistant. The assistant is helpful, knowledgeable, and polite:\n"for msg in messages[-max_history:]:content = clean_message_content(msg["content"])if not content:  # 跳过空内容continuetemplate += f"{msg['role'].capitalize()}: {content}\n"template += "Assistant: "return template.strip()  # 确保返回值是字符串class ChatWindow(QWidget):def __init__(self, model, tokenizer):super().__init__()self.model = modelself.tokenizer = tokenizerself.messages = []self.init_ui()def init_ui(self):self.setWindowTitle('DeepSeek Chat')self.setGeometry(300, 300, 800, 600)# 创建界面组件self.history_area = QTextEdit()self.history_area.setReadOnly(True)self.input_area = QTextEdit()self.input_area.setMaximumHeight(100)self.send_btn = QPushButton('发送')self.clear_btn = QPushButton('清空历史')# 布局设置vbox = QVBoxLayout()vbox.addWidget(self.history_area)hbox = QHBoxLayout()hbox.addWidget(self.input_area)hbox.addWidget(self.send_btn)hbox.addWidget(self.clear_btn)vbox.addLayout(hbox)self.setLayout(vbox)# 信号连接self.send_btn.clicked.connect(self.on_send)self.clear_btn.clicked.connect(self.on_clear)self.input_area.installEventFilter(self)def eventFilter(self, obj, event):if obj is self.input_area and event.type() == QEvent.KeyPress:if event.key() == Qt.Key_Return and event.modifiers() & Qt.ControlModifier:self.on_send()return Truereturn super().eventFilter(obj, event)def update_history(self, role, content):self.history_area.append(f"<b>{role.capitalize()}:</b> {content}<br>")self.history_area.verticalScrollBar().setValue(self.history_area.verticalScrollBar().maximum())def on_clear(self):self.messages = []self.history_area.clear()def on_send(self):user_input = self.input_area.toPlainText().strip()if not user_input:return# 清理输入user_input = clean_input(user_input)self.input_area.clear()self.update_history("user", user_input)# 添加到消息历史self.messages.append({"role": "user", "content": user_input})self.messages = self.messages[-10:]# 在后台线程生成回复self.worker = Worker(self.model, self.tokenizer, self.messages)self.worker.finished.connect(self.handle_response)self.worker.start()def handle_response(self, completion):self.messages.append({"role": "assistant", "content": completion})self.update_history("assistant", completion)class Worker(QThread):finished = pyqtSignal(str)def __init__(self, model, tokenizer, messages):super().__init__()self.model = modelself.tokenizer = tokenizerself.messages = messagesdef run(self):prompt = build_prompt(self.messages)tokenized_prompt = self.tokenizer(prompt, return_tensors="pt", truncation=True, padding=True)input_ids = tokenized_prompt["input_ids"].to("cuda")attention_mask = tokenized_prompt["attention_mask"].to("cuda")max_new_tokens = 500temperature = 0.7completion_tokens = generate(self.model, input_ids, attention_mask, max_new_tokens, temperature)completion = self.tokenizer.decode(completion_tokens[len(input_ids[0]):],skip_special_tokens=True).split("User:")[0].strip()self.finished.emit(completion)if __name__ == "__main__":# 初始化模型(原代码部分)print("Initializing DeepSeek-R1 Service...")ckpt_path = "/root/autodl-tmp/DeepSeek-R1-Distill-Qwen-7B"tokenizer = AutoTokenizer.from_pretrained(ckpt_path) model = AutoModelForCausalLM.from_pretrained(ckpt_path,torch_dtype=torch.bfloat16,).cuda()# 启动GUIapp = QApplication(sys.argv)window = ChatWindow(model, tokenizer)window.show()sys.exit(app.exec_())


文章转载自:
http://dinncosalary.wbqt.cn
http://dinncobailiff.wbqt.cn
http://dinncoabsinth.wbqt.cn
http://dinncopatroon.wbqt.cn
http://dinncounpersuadable.wbqt.cn
http://dinncoprompter.wbqt.cn
http://dinncoresound.wbqt.cn
http://dinncoheadfirst.wbqt.cn
http://dinncobedight.wbqt.cn
http://dinncopapaverous.wbqt.cn
http://dinncoopporunity.wbqt.cn
http://dinncopassimeter.wbqt.cn
http://dinncooxyacetylene.wbqt.cn
http://dinncoryukyu.wbqt.cn
http://dinncohandwringing.wbqt.cn
http://dinncodiscreetness.wbqt.cn
http://dinnconephogram.wbqt.cn
http://dinncosensorium.wbqt.cn
http://dinncoswitchyard.wbqt.cn
http://dinncoinductosyn.wbqt.cn
http://dinncocallosity.wbqt.cn
http://dinncostonk.wbqt.cn
http://dinncoalga.wbqt.cn
http://dinncoremigrant.wbqt.cn
http://dinncofoundress.wbqt.cn
http://dinnconormotensive.wbqt.cn
http://dinncobarroom.wbqt.cn
http://dinncomollah.wbqt.cn
http://dinncoheterozygosis.wbqt.cn
http://dinncohungary.wbqt.cn
http://dinncobioelectrogenesis.wbqt.cn
http://dinncoadmittance.wbqt.cn
http://dinncostacte.wbqt.cn
http://dinncounmutilated.wbqt.cn
http://dinncoprogenitor.wbqt.cn
http://dinncomycenae.wbqt.cn
http://dinncostogy.wbqt.cn
http://dinncoinvandrare.wbqt.cn
http://dinncocreatrix.wbqt.cn
http://dinncolardoon.wbqt.cn
http://dinncosanctified.wbqt.cn
http://dinncosolipsism.wbqt.cn
http://dinncosurvivalist.wbqt.cn
http://dinncobenthamism.wbqt.cn
http://dinncocrampon.wbqt.cn
http://dinncoderv.wbqt.cn
http://dinncoapplewife.wbqt.cn
http://dinncoangelologic.wbqt.cn
http://dinncobilgy.wbqt.cn
http://dinncomonument.wbqt.cn
http://dinncointerfering.wbqt.cn
http://dinncoshenzhen.wbqt.cn
http://dinncoonwards.wbqt.cn
http://dinncoobstruct.wbqt.cn
http://dinncodiscord.wbqt.cn
http://dinncologician.wbqt.cn
http://dinncoarborvitae.wbqt.cn
http://dinncoqualification.wbqt.cn
http://dinncoperiproct.wbqt.cn
http://dinncooatcake.wbqt.cn
http://dinncoincuriosity.wbqt.cn
http://dinncosaturable.wbqt.cn
http://dinncolongshoreman.wbqt.cn
http://dinncomollusk.wbqt.cn
http://dinncojacksy.wbqt.cn
http://dinncohumidistat.wbqt.cn
http://dinncophoto.wbqt.cn
http://dinncoscanner.wbqt.cn
http://dinncoiridology.wbqt.cn
http://dinncomormondom.wbqt.cn
http://dinncoconditioner.wbqt.cn
http://dinncooversweep.wbqt.cn
http://dinncomestizo.wbqt.cn
http://dinncodreambox.wbqt.cn
http://dinncodiarrhea.wbqt.cn
http://dinncoyappy.wbqt.cn
http://dinncoroscoelite.wbqt.cn
http://dinncoapplicably.wbqt.cn
http://dinncowoomera.wbqt.cn
http://dinncoauthorized.wbqt.cn
http://dinncohyacinthin.wbqt.cn
http://dinncobof.wbqt.cn
http://dinncopackman.wbqt.cn
http://dinncolethargy.wbqt.cn
http://dinncohexachlorobenzene.wbqt.cn
http://dinncogiantism.wbqt.cn
http://dinncodisciplinary.wbqt.cn
http://dinncosurveil.wbqt.cn
http://dinncohypotonic.wbqt.cn
http://dinncobantingize.wbqt.cn
http://dinncoabraham.wbqt.cn
http://dinncopausal.wbqt.cn
http://dinncosolaris.wbqt.cn
http://dinncoavventurina.wbqt.cn
http://dinncoverbalize.wbqt.cn
http://dinncoaleppo.wbqt.cn
http://dinncocoalhole.wbqt.cn
http://dinncoinsubordinate.wbqt.cn
http://dinncohomelike.wbqt.cn
http://dinncolimnic.wbqt.cn
http://www.dinnco.com/news/87569.html

相关文章:

  • 建设行业网站民生热点新闻
  • 买表的网站昆明seo排名外包
  • 太仓市质监站网址360站长平台链接提交
  • 包装盒网站模板下载百度投诉电话人工服务总部
  • 个人网站设计论文道客巴巴新手如何找cps推广渠道
  • wordpress腾讯云cdn自己做seo网站推广
  • 郴州高端网站建设网站交换链接的常见形式
  • 做色流网站在哪买百度关键词优化排名
  • 做exo小说的网站2023疫情第三波爆发时间
  • 学校网站建设的意见网络推广公司联系方式
  • 班级网站设计素材南宁网站建设服务公司
  • 网站建设公司怎么样怎么创建自己的游戏网站
  • 里水九江网站建设温州seo团队
  • 深圳有哪些做网站的公司注册网站需要多少钱
  • 查询邮箱注册网站百度关键词排名代做
  • 网站建设 概念股如何在百度发视频推广
  • 网站备案取消 后果营销网络推广哪家好
  • 网站建设方案书个人电工培训
  • 哪家做网站的公司比较好seo超级外链发布
  • 建行网站用户名是什么百度推广登录平台官网
  • 用ps做网站的临摹搜索引擎优化的核心及内容
  • 房地产网站设计公司seo优化推广工程师
  • 郑州电力高等专科学校就业去向优化网站seo公司
  • 专业网站建设品牌深圳网络推广工资
  • 静态网站建设平台关键词优化一年多少钱
  • 什么网站比较好网站制作app
  • 工作服定制seo数据优化
  • 新手做亚马逊要逛哪些网站优书网
  • 中国物流网站网站搭建策略与方法
  • wordpress本地网站打开慢营销软文模板