fix loading chatglm3 (#1937)

* update welcome svg

* update welcome message

* fix loading chatglm3

---------

Co-authored-by: binary-husky <qingxu.fu@outlook.com>
Co-authored-by: binary-husky <96192199+binary-husky@users.noreply.github.com>
这个提交包含在:
moetayuko
2024-08-19 23:32:45 +08:00
提交者 GitHub
父节点 5010537f3c
当前提交 a95b3daab9
共有 3 个文件被更改,包括 32 次插入22 次删除

查看文件

@@ -18,7 +18,7 @@ class GetGLM3Handle(LocalLLMHandle):
def load_model_and_tokenizer(self): def load_model_and_tokenizer(self):
# 🏃‍♂️🏃‍♂️🏃‍♂️ 子进程执行 # 🏃‍♂️🏃‍♂️🏃‍♂️ 子进程执行
from transformers import AutoModel, AutoTokenizer from transformers import AutoModel, AutoTokenizer, BitsAndBytesConfig
import os, glob import os, glob
import os import os
import platform import platform
@@ -45,15 +45,13 @@ class GetGLM3Handle(LocalLLMHandle):
chatglm_model = AutoModel.from_pretrained( chatglm_model = AutoModel.from_pretrained(
pretrained_model_name_or_path=_model_name_, pretrained_model_name_or_path=_model_name_,
trust_remote_code=True, trust_remote_code=True,
device="cuda", quantization_config=BitsAndBytesConfig(load_in_4bit=True),
load_in_4bit=True,
) )
elif LOCAL_MODEL_QUANT == "INT8": # INT8 elif LOCAL_MODEL_QUANT == "INT8": # INT8
chatglm_model = AutoModel.from_pretrained( chatglm_model = AutoModel.from_pretrained(
pretrained_model_name_or_path=_model_name_, pretrained_model_name_or_path=_model_name_,
trust_remote_code=True, trust_remote_code=True,
device="cuda", quantization_config=BitsAndBytesConfig(load_in_8bit=True),
load_in_8bit=True,
) )
else: else:
chatglm_model = AutoModel.from_pretrained( chatglm_model = AutoModel.from_pretrained(

查看文件

@@ -7,7 +7,7 @@ tiktoken>=0.3.3
requests[socks] requests[socks]
pydantic==2.5.2 pydantic==2.5.2
protobuf==3.18 protobuf==3.18
transformers>=4.27.1 transformers>=4.27.1,<4.42
scipdf_parser>=0.52 scipdf_parser>=0.52
anthropic>=0.18.1 anthropic>=0.18.1
python-markdown-math python-markdown-math

查看文件

@@ -8,7 +8,7 @@ class WelcomeMessage {
url: "https://github.com/binary-husky/gpt_academic/wiki/%E9%A1%B9%E7%9B%AE%E9%85%8D%E7%BD%AE%E8%AF%B4%E6%98%8E", url: "https://github.com/binary-husky/gpt_academic/wiki/%E9%A1%B9%E7%9B%AE%E9%85%8D%E7%BD%AE%E8%AF%B4%E6%98%8E",
}, },
{ {
title: "Arxiv论文一键翻译", title: "Arxiv论文翻译",
content: "无缝切换学术阅读语言,最优英文转中文的学术论文阅读体验。", content: "无缝切换学术阅读语言,最优英文转中文的学术论文阅读体验。",
svg: "file=themes/svg/arxiv.svg", svg: "file=themes/svg/arxiv.svg",
url: "https://www.bilibili.com/video/BV1dz4y1v77A/", url: "https://www.bilibili.com/video/BV1dz4y1v77A/",
@@ -67,6 +67,18 @@ class WelcomeMessage {
svg: "file=themes/svg/check.svg", svg: "file=themes/svg/check.svg",
url: "https://github.com/binary-husky/gpt_academic/wiki", url: "https://github.com/binary-husky/gpt_academic/wiki",
}, },
{
title: "接入更多新模型",
content: "模型迭代日新月异,一起动手接入更多新的在线或本地大模型吧。",
svg: "file=themes/svg/box.svg",
url: "https://github.com/binary-husky/gpt_academic/blob/master/request_llms/README.md",
},
{
title: "联动VLLM等服务",
content: "借助VLLM和OneApi等第三方服务高效地部署和运行大模型。",
svg: "file=themes/svg/location.svg",
url: "https://github.com/binary-husky/gpt_academic/wiki/如何更便捷地接入one-api",
},
]; ];
this.visible = false; this.visible = false;
this.max_welcome_card_num = 6; this.max_welcome_card_num = 6;
@@ -99,7 +111,7 @@ class WelcomeMessage {
}, 1); }, 1);
} }
} }
async reflesh_cards() { async reflesh_cards() {
if (!this.visible){ if (!this.visible){
return; return;
@@ -121,7 +133,7 @@ class WelcomeMessage {
if (index >= this.max_welcome_card_num) { if (index >= this.max_welcome_card_num) {
break; break;
} }
const card = this.card_array[index]; const card = this.card_array[index];
// 已经包含了 hide 属性? // 已经包含了 hide 属性?
if (card.classList.contains('hide') || card.classList.contains('show')) { if (card.classList.contains('hide') || card.classList.contains('show')) {
@@ -151,9 +163,9 @@ class WelcomeMessage {
card.classList.add('show'); card.classList.add('show');
}, { once: true }); }, { once: true });
card.classList.add('hide'); card.classList.add('hide');
// 等待 250 毫秒 // 等待 250 毫秒
await new Promise(r => setTimeout(r, 200)); await new Promise(r => setTimeout(r, 200));
} }
@@ -162,22 +174,22 @@ class WelcomeMessage {
shuffle(array) { shuffle(array) {
var currentIndex = array.length, randomIndex; var currentIndex = array.length, randomIndex;
// While there remain elements to shuffle... // While there remain elements to shuffle...
while (currentIndex != 0) { while (currentIndex != 0) {
// Pick a remaining element... // Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex); randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--; currentIndex--;
// And swap it with the current element. // And swap it with the current element.
[array[currentIndex], array[randomIndex]] = [ [array[currentIndex], array[randomIndex]] = [
array[randomIndex], array[currentIndex]]; array[randomIndex], array[currentIndex]];
} }
return array; return array;
} }
async update() { async update() {
// console.log('update') // console.log('update')
var page_width = document.documentElement.clientWidth; var page_width = document.documentElement.clientWidth;
@@ -189,7 +201,7 @@ class WelcomeMessage {
this.card_array = []; this.card_array = [];
this.static_welcome_message_previous = []; this.static_welcome_message_previous = [];
} }
return; return;
} }
if (this.visible){ if (this.visible){
return; return;
@@ -245,7 +257,7 @@ class WelcomeMessage {
// 创建一个新的div元素 // 创建一个新的div元素
const welcome_card_container = document.createElement('div'); const welcome_card_container = document.createElement('div');
welcome_card_container.classList.add('welcome-card-container'); welcome_card_container.classList.add('welcome-card-container');
// 创建主标题 // 创建主标题
const major_title = document.createElement('div'); const major_title = document.createElement('div');
major_title.classList.add('welcome-title'); major_title.classList.add('welcome-title');
@@ -264,7 +276,7 @@ class WelcomeMessage {
}); });
elem_chatbot.appendChild(welcome_card_container); elem_chatbot.appendChild(welcome_card_container);
// 添加显示动画 // 添加显示动画
requestAnimationFrame(() => { requestAnimationFrame(() => {
welcome_card_container.classList.add('show'); welcome_card_container.classList.add('show');
@@ -297,11 +309,11 @@ class PageFocusHandler {
constructor() { constructor() {
this.hasReturned = false; this.hasReturned = false;
this.focusCallbacks = []; this.focusCallbacks = [];
// Bind the focus and blur event handlers // Bind the focus and blur event handlers
window.addEventListener('visibilitychange', this.handleFocus.bind(this)); window.addEventListener('visibilitychange', this.handleFocus.bind(this));
} }
// Method to handle the focus event // Method to handle the focus event
handleFocus() { handleFocus() {
if (this.hasReturned) { if (this.hasReturned) {
@@ -309,7 +321,7 @@ class PageFocusHandler {
} }
this.hasReturned = true; this.hasReturned = true;
} }
// Method to add a custom callback function // Method to add a custom callback function
addFocusCallback(callback) { addFocusCallback(callback) {
if (typeof callback === 'function') { if (typeof callback === 'function') {