首页/文章/ 详情

GPT4all---本地部署的微型大语言模型

1年前浏览4669
1 引言

ChatGPT的诞生促使许多自然语言处理公司部署本地的大语言模型产品,其中最有影响力的是LLaMA(Large Language Model Meta AI)。Meta声称LLaMA的规模仅为竞争对手 ChatGPT 的十分之一,但性能却优于GPT-3模型。然而,LLaMA的模型大约有200G,对普通计算机来说仍然很难运行起来,于是出现了更加微型的大语言模型---GPT4all,GPT4all不使用GPU即可运行,不过不用试验也可以想象得到,它与ChatGPT的距离应该还相差甚远。本文描述了在本地部署GPT4all的过程。


2 安装和试验

从GPT4all的网站上下载Windows版本(gpt4all-installer-win64.exe),安装的过程中需要下载语言模型ggml-gpt4all-j-v1.2-jazzy.bin,这个文件大约3.7G,安装完成后,执行/bin/chat.exe,便进入对话系统:
测试一个问题:"What is rock mechanics?",它给出的回答基本上正确,但如上图显示,它出现了很多重复的回答,有点儿凑字数的感觉,其实就回答了一句话:"岩石力学是力学的一个分支,用于研究岩石和矿物在应力和应变下的行为。"。当问到3DEC,FLACD, PFC这些软件时,便开始胡说八道了。显然这个模型的功能还很差。

3 与Langchain连接

Langchain提供了与GPT4all的接口【LangChain---大型语言模型(LLM)的标准接口使用大语言模型实现与岩土数据集GeotechSet的对话---DFN试验】,首先需要安装模块:

pip install pyllamacpp
此外,安装系统时自带的模型ggml-gpt4all-j-v1.2-jazzy.bin不是最新的,需要下载最新的模型gpt4all-lora-quantized-ggml.bin,这个模型大约4.1G,更要命的是这个模型还需要转换,转换文件为migrate-ggml-2023-03-30-pr613.py,转换命令如下:

python migrate-ggml-2023-03-30-pr613.py /gpt4all-lora-quantized-ggml.bin ggml-new.bin
与Langchain连接的代码如下(gtp-4-all.py):













from langchain import PromptTemplate, LLMChainfrom langchain.llms import GPT4Allfrom langchain.callbacks.base import CallbackManagerfrom langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandlerprompt = PromptTemplate(template=template, input_variables=["question"])local_path = 'ggml-new.bin' # Callbacks support token-wise streamingcallback_manager = CallbackManager([StreamingStdOutCallbackHandler()])# Verbose is required to pass to the callback managerllm = GPT4All(model=local_path, callback_manager=callback_manager, verbose=True)llm_chain = LLMChain(prompt=prompt, llm=llm)question = "What is rock mechanics?"llm_chain.run(question)
现在问同一个问题:"What is rock mechaincs?",它给出的回答如下:
1) Rock materials are very important in civil engineering and architecture, because they form the foundation of buildings & structures. So it makes sense to study them more scientifically for their characteristics such as strength or compressibility which can be used intelligently on construction sites to avoid any collapse/damage due to faulty building designs. 岩石材料在土木工程和建筑中非常重要,因为它们是建筑物和结构的基础。因此,更科学地研究它们的特性是有意义的,如强度或可压缩性,这可以在建筑工地上巧妙地使用,以避免因错误的建筑设计而造成任何坍塌/损坏。
2) The science behind this is called Rock Mechanics (RM). RM involves the application of principles and methods from geology, physics & mechanics for studying the properties of rock materials such as strength or compressibility which can be used intelligently on construction sites. 这背后的科学被称为岩石力学。岩石力学涉及应用地质学、物理学和力学的原理和方法来研究岩石材料的特性,如强度或可压缩性,可以在建筑工地上巧妙地使用。
3) This field has applications in civil engineering to monitor changes that might occur due to forces exerted by people walking/standing etc., over time. It also helps identify and classify rocks into various classes based upon their mechanical properties, such as the strength or elasticity of rock strata underground. 这一领域在土木工程中的应用是为了监测由于人们行走/站立等所施加的力量而可能发生的变化,随着时间的推移。它还有助于根据岩石的力学性能,如地下岩层的强度或弹性,识别岩石并将其分为不同等级。
4) Rock mechanics can be divided in three main branches: 1-Exploration geophysical survey for identifying mineral deposits;2-Study and designation method to identify rocks according their properties (strength, fracture);3--Characterization of rock materials with respect to soil  岩石力学可分为三个主要分支:1-勘探地球物理调查,以确定矿藏;2-研究和指定方法,根据岩石的特性(强度、断裂)来确定岩石;3-岩石材料与土的特性。

这个回答虽然很详细,但显而易见,存在着许多错误说法。

4 与GPT-4的对比
《计算岩土力学》已经全面接入了GPT-4。作为对比,下面显示的是GPT-4对"What is rock mechanics"的回答:
Rock mechanics is a branch of geotechnical engineering and applied science that deals with the behavior of rocks and rock masses in response to various physical and environmental conditions. It is an interdisciplinary field that combines principles from geology, engineering, and materials science to study the mechanical properties, behavior, and failure mechanisms of rocks, as well as their applications in engineering projects.Rock mechanics is important for understanding and addressing issues related to rock excavation, tunneling, mining, petroleum extraction, slope stability, and the design of foundations for structures built on or within rock formations. It also plays a crucial role in the assessment of natural hazards, such as earthquakes, landslides, and rockfalls. By understanding the mechanical behavior of rocks, engineers can design safer and more efficient structures and infrastructure, while also mitigating potential hazards. 岩石力学是岩土工程和应用科学的一个分支,涉及岩石和岩体在各种物理和环境条件下的行为。岩石力学是一个跨学科的领域,结合了地质学、工程学和材料科学的原理,研究岩石的力学性能、行为和破坏机制,以及它们在工程项目中的应用。岩石力学对于理解和解决与岩石开挖、隧道开挖、采矿、石油开采、边坡稳定性以及在岩层上或岩层内建造的结构的基础设计有关的问题很重要。它在评估自然灾害,如地震、滑坡和落石方面也发挥着关键作用。通过了解岩石的力学行为,工程师可以设计出更安全、更有效的结构和基础设施,同时也可以减轻潜在的危险。
5 结束语
作为一个开源并且能够在普通计算机上顺利运行的大语言模型,GPT4all已经迈出了很大一步,当然目前还不可能与ChatGPT和GPT-4相提并论。不过,GPT4all可以在普通机器上训练自己的数据,我们将作进一步的试验。

来源:计算岩土力学
断裂建筑python岩土PFC3DEC材料试验
著作权归作者所有,欢迎分享,未经许可,不得转载
首次发布时间:2023-05-09
最近编辑:1年前
计算岩土力学
传播岩土工程教育理念、工程分析...
获赞 138粉丝 992文章 1776课程 0
点赞
收藏
未登录
还没有评论
课程
培训
服务
行家
VIP会员 学习 福利任务 兑换礼品
下载APP
联系我们
帮助与反馈