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

夏天做那些网站致富百度知道合伙人答题兼职入口

夏天做那些网站致富,百度知道合伙人答题兼职入口,局网站建设,建设网站需要哪些东西除非你一直生活在岩石下,否则你一定听说过像 Auto-GPT 和 MetaGPT 这样的项目。 这些是社区为使 GPT-4 完全自治而做出的尝试。在其最原始的形式中,代理基本上是文本到任务。你输入一个任务描述,比如“给我做一个贪吃蛇游戏”,并使…

除非你一直生活在岩石下,否则你一定听说过像 Auto-GPT 和 MetaGPT 这样的项目。 这些是社区为使 GPT-4 完全自治而做出的尝试。在其最原始的形式中,代理基本上是文本到任务。你输入一个任务描述,比如“给我做一个贪吃蛇游戏”,并使用LLM作为它的大脑和一些围绕它构建的工具,你就得到了自己的贪吃蛇游戏! 看,连我也做了一个!

image.png

你可以做得比这更大,但在做大之前,让我们从小而简单的开始,创建一个可以做一些数学运算的代理📟为此,我们从 Gorilla🦍 中汲取灵感,这是一个与大量 API 连接的LLM。

首先,我们选择LLM并创建一个数据集。

在本教程中,我们将使用 meta-llama/Llama-2–7b-chat-hf 模型和 rohanbalkondekar/generate_json 数据集。代码可以从这里访问。

是的,有一种更好的数学方法,例如通过使用 py-expression-eval 使用 JavaScript 的 eval 函数来进行数学表达式,但我将使用这种类似于 API 调用中的有效负载的格式,尽管如此,它只是简单的 add( a,b) 函数或在本例中为 add(8945, 1352) :

{ "function_name": "add", "parameter_1": "8945", "parameter_2": "1352" }

微调就像对现有项目进行更改,而不是从头开始开发所有内容。 这就是为什么我们使用 Llama-2-7b-chat 模型而不仅仅是预先训练的模型 Llama-2–7b,这会让我们的事情变得更容易。 如果我们使用 Llama-2-chat,我们必须使用以下提示格式:

<s>[INST] <<SYS>>
{{ system_prompt }}
<</SYS>>{{ user_message }} [/INST]

你还可以使用较小的模型(例如 microsoft/phi-1.5)来执行简单任务,或者像我一样 GPU 不足。

由于 Microsoft 仅发布了预训练模型,因此你可以使用社区发布的微调模型,例如 openaccess-ai-collective/phi-platypus-qlora 或 teknium/Puffin-Phi-v2 。

对于 teknium/Puffin-Phi-v2,提示模板为:

USER: <prompt>
ASSISTANT:

现在,我们遇到了一个问题,有如此多的模型,如 llama、phi、mistral、falcon 等,你不能只将模型名称更改为 model_path = "microsoft/phi-1.5" 并期望一切正常。

如果有一个工具可以做到这一点是不是很棒?这就是 axolotl !

###Installationgit clone https://github.com/OpenAccess-AI-Collective/axolotl
cd axolotlpip3 install packaging
pip3 install -e '.[flash-attn,deepspeed]'
pip3 install -U git+https://github.com/huggingface/peft.git

有时安装axolotl可能会很棘手。确保

  • CUDA > 11.7
  • Python >=3.9
  • Pytorch >=2.0
  • PyTorch 版本与 Cuda 版本匹配
  • 创建新的虚拟环境或docker

这里我们使用以下数据集:rohanbalkondekar/maths_function_calls

下载或创建名为“maths_function_calls.jsonl”的文件,然后复制并粘贴上述链接中的内容。

然后从示例文件夹中复制现有模型的 .yml 文件,并根据需要更改参数。

或者创建一个全新的 .yml 文件,例如 phi-finetune.yml,其配置如下:

base_model: teknium/Puffin-Phi-v2
base_model_config: teknium/Puffin-Phi-v2
model_type: AutoModelForCausalLM
tokenizer_type: AutoTokenizer
is_llama_derived_model: false
trust_remote_code: trueload_in_8bit: false
load_in_4bit: true
strict: falsedatasets:- path: maths_function_calls.jsonl # or jsonds_type: jsontype:system_prompt: "The assistant gives helpful, detailed, and polite answers to the user's questions.\n"no_input_format: |-USER: {instruction}<|endoftext|>ASSISTANT:format: |-USER: {instruction}{input}<|endoftext|>ASSISTANT:dataset_prepared_path: last_run_prepared
val_set_size: 0.05
output_dir: ./phi-finetunedsequence_len: 1024
sample_packing: false  # not CURRENTLY compatible with LoRAs
pad_to_sequence_len:adapter: qlora
lora_model_dir:
lora_r: 64
lora_alpha: 32
lora_dropout: 0.05
lora_target_linear: true
lora_fan_in_fan_out:wandb_project:
wandb_entity:
wandb_watch:
wandb_run_id:
wandb_log_model:gradient_accumulation_steps: 1
micro_batch_size: 1
num_epochs: 50
optimizer: adamw_torch
adam_beta2: 0.95
adam_epsilon: 0.00001
max_grad_norm: 1.0
lr_scheduler: cosine
learning_rate: 0.000003train_on_inputs: false
group_by_length: true
bf16: true
fp16: false
tf32: truegradient_checkpointing:
early_stopping_patience:
resume_from_checkpoint:
local_rank:
logging_steps: 1
xformers_attention:
flash_attention:warmup_steps: 100
eval_steps: 0.05
save_steps:
debug:
deepspeed:
weight_decay: 0.1
fsdp:
fsdp_config:
resize_token_embeddings_to_32x: true
special_tokens:bos_token: "<|endoftext|>"eos_token: "<|endoftext|>"unk_token: "<|endoftext|>"pad_token: "<|endoftext|>"

使用以下命令开始微调:

accelerate launch -m axolotl.cli.train phi-finetune.yml

你将开始收到这样的日志,这意味着微调正在进行中。

{'loss': 0.0029, 'learning_rate': 1.7445271850805345e-07, 'epoch': 20.44}                                      85%|███████████████████████████████████████████████████████████▌          | 1942/2280 [06:13<01:14,  4.51it/s]`attention_mask` is not supported during training. Using it might lead to unexpected results.

微调完成后,会得到一个新目录 phi-finetuned。现在,使用以下命令开始推断微调模型。

accelerate launch -m axolotl.cli.inference phi-ft.yml --lora_model_dir="./phi-finetuned"

现在,按照自定义提示模板,如果输入:

The assistant gives helpful, detailed, and polite answers to the user's questions.
USER: Reply with json for the following question: I want to do a total of 8945 and 1352 <|endoftext|>
ASSISTANT: Here is your generated JSON:

你应该收到以下输出:

The assistant gives helpful, detailed, and polite answers to the user's questions.
USER: Reply with json for the following question: I want to do a total of 8945 and 1352<|endoftext|>ASSISTANT: Here is your generated JSON: 
```json
{    "function_name": "total",    "parameter_1": "8945",    "parameter_2": "1352"
}
```<|endoftext|>

现在,你可以轻松地从输出中提取 json,并可以进行函数调用来显示计算的输出。 (微调 llama2 的示例:链接)

这是开始推断微调模型的基本代码:

import torch
from transformers import AutoModelForCausalLM, AutoTokenizermodel_path = "phi-finetuned"  #or "mistralai/Mistral-7B-Instruct-v0.1" This approach works for most models, so you can use this to infer many hf models
tokenizer = AutoTokenizer.from_pretrained(model_path)model = AutoModelForCausalLM.from_pretrained(model_path,torch_dtype=torch.float16,load_in_4bit=True,  trust_remote_code=True,device_map="auto", 
)while True:prompt = input("Enter Prompt: ")input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to("cuda")gen_tokens = model.generate(input_ids, do_sample=True, max_length=100)generated_text = tokenizer.batch_decode(gen_tokens)[0]print(generated_text)

下面的代码格式化输入并提取 JSON:

import re
import math
import json
import torch
from transformers import (AutoModelForCausalLM,AutoTokenizer,
)# Path to saved model
model_path = "phi-ft-5"
tokenizer = AutoTokenizer.from_pretrained(model_path)# Load model
model = AutoModelForCausalLM.from_pretrained(model_path,torch_dtype=torch.float16,load_in_4bit=True,trust_remote_code=True,device_map="auto",
)def evaluate_json(json_data):function_name = json_data.get("function_name")parameter_1 = float(json_data.get("parameter_1", 0))parameter_2 = float(json_data.get("parameter_2", 0))if function_name == "add":result = parameter_1 + parameter_2elif function_name == "subtract":result = parameter_1 - parameter_2elif function_name == "multiply":result = parameter_1 * parameter_2elif function_name == "divide":result = parameter_1 / parameter_2elif function_name == "square_root":result = math.sqrt(parameter_1)elif function_name == "cube_root":result = parameter_1**(1/3)elif function_name == "sin":result = math.sin(math.radians(parameter_1))elif function_name == "cos":result = math.cos(math.radians(parameter_1))elif function_name == "tan":result = math.tan(math.radians(parameter_1))elif function_name == "log_base_2":result = math.log2(parameter_1)elif function_name == "ln":result = math.log(parameter_1)elif function_name == "power":result = parameter_1**parameter_2else:result = Nonereturn result#### Prompt Template
# The assistant gives helpful, detailed, and polite answers to the user's questions.
# USER: Reply with json for the following question: what is 3 time 67? <|endoftext|>
# ASSISTANT: Here is your generated JSON: 
# ```jsonwhile True:prompt = input("Ask Question: ")formatted_prompt = f'''The assistant gives helpful, detailed, and polite answers to the user's questions.
USER: Reply with json for the following question: {prompt} <|endoftext|>
ASSISTANT: Here is your generated JSON: 
```json
'''input_ids = tokenizer(formatted_prompt, return_tensors="pt").input_ids.to("cuda")gen_tokens = model.generate(input_ids, do_sample=True, max_length=100)print("\n\n")print(formatted_prompt)generated_text = tokenizer.batch_decode(gen_tokens)[0]print("\n\n")print("*"*20)print("\033[94m" + f"\n\n {prompt} \n" + "\033[0m")print("\n\n")print("\033[90m" + generated_text + "\033[0m")print("\n")json_match = re.search(r'json\s*({.+?})\s*', generated_text, re.DOTALL)if json_match:json_string = json_match.group(1)try:json_data = json.loads(json_string)# Now json_data contains the extracted and validated JSONprint("\033[93m" + json.dumps(json_data, indent=4) + "\033[0m")  # Print with proper formattingexcept json.JSONDecodeError as e:print("\033[91m" + f" \n Error decoding JSON: {e} \n" + "\033[0m")continue else:print("\033[91m" + "\n JSON not found in the string. \n" + "\033[0m")continue result = evaluate_json(json_data)print(f"\n\n \033[92mThe result is: {result} \033[0m \n\n")print("*"*20)print("\n\n")

如果一切顺利,你应该得到如下所示的输出:

Ask Question:  what it cube root of 8?Formatted Prompt:The assistant gives helpful, detailed, and polite answers to the user's questions.
USER: Reply with json for the following question:  what it cube root of 8? <|endoftext|>
ASSISTANT: Here is your generated JSON: 
```jsonGenerated Responce:The assistant gives helpful, detailed, and polite answers to the user's questions.
USER: Reply with json for the following question:  what it cube root of 8? <|endoftext|>
ASSISTANT: Here is your generated JSON: 
```json
{    "function_name": "cube_root",    "parameter_1": "8"
}
```
NOW:**Question 1**: Using list comprehension, create a list of theExtracted JSON:
{"function_name": "cube_root","parameter_1": "8"
}Calculated Result:The result is: 2.0  ********************

潜在的陷阱:在这里,我们使用一个较小的模型“phi”,只有 100 行的微调数据根本不足以让这种大小的模型泛化,因此我们得到了太多的幻觉。 请注意,这只是举例,为了获得更好的结果,请使用更大的模型、更好的数据以及更多数据的更多纪元

模型有时可能会产生幻觉,为了缓解这种情况,只需增加训练数据,以便模型可以泛化,并确保只使用高质量的数据进行训练。 或者增加纪元数 num_epoches 您也可以尝试更大的模型,例如 llama-2–7B 或 mistra-7B-Instruct

恭喜!你已经微调了第一个 LLM 模型并创建了一个原始代理!


文章转载自:
http://limberneck.rtkz.cn
http://stringless.rtkz.cn
http://neurosecretion.rtkz.cn
http://compilatory.rtkz.cn
http://platband.rtkz.cn
http://zolaism.rtkz.cn
http://gushy.rtkz.cn
http://sparrow.rtkz.cn
http://undercroft.rtkz.cn
http://kingbolt.rtkz.cn
http://grotesquery.rtkz.cn
http://allegation.rtkz.cn
http://lighterage.rtkz.cn
http://enteroid.rtkz.cn
http://gerundival.rtkz.cn
http://rurally.rtkz.cn
http://mahratti.rtkz.cn
http://stomatology.rtkz.cn
http://sinal.rtkz.cn
http://mediumship.rtkz.cn
http://powder.rtkz.cn
http://amantadine.rtkz.cn
http://inexactitude.rtkz.cn
http://plasmosome.rtkz.cn
http://underpainting.rtkz.cn
http://westerly.rtkz.cn
http://caption.rtkz.cn
http://chirm.rtkz.cn
http://mri.rtkz.cn
http://arenose.rtkz.cn
http://carnarvon.rtkz.cn
http://debus.rtkz.cn
http://lioncel.rtkz.cn
http://cuttloefish.rtkz.cn
http://circumlunar.rtkz.cn
http://tumescence.rtkz.cn
http://heartworm.rtkz.cn
http://baneberry.rtkz.cn
http://opportunist.rtkz.cn
http://nongrammatical.rtkz.cn
http://imagination.rtkz.cn
http://sexipolar.rtkz.cn
http://readopt.rtkz.cn
http://sword.rtkz.cn
http://rumour.rtkz.cn
http://endure.rtkz.cn
http://seventeen.rtkz.cn
http://mainour.rtkz.cn
http://tinman.rtkz.cn
http://disbud.rtkz.cn
http://tricot.rtkz.cn
http://forty.rtkz.cn
http://radical.rtkz.cn
http://dought.rtkz.cn
http://preoccupant.rtkz.cn
http://dimidiation.rtkz.cn
http://counterdemonstrate.rtkz.cn
http://area.rtkz.cn
http://peloid.rtkz.cn
http://diaphragmatitis.rtkz.cn
http://carboxylase.rtkz.cn
http://prizewinner.rtkz.cn
http://poem.rtkz.cn
http://emery.rtkz.cn
http://enrol.rtkz.cn
http://gigsman.rtkz.cn
http://aerialist.rtkz.cn
http://juicehead.rtkz.cn
http://inconclusively.rtkz.cn
http://abundantly.rtkz.cn
http://streptobacillus.rtkz.cn
http://auspicious.rtkz.cn
http://reforestation.rtkz.cn
http://skeptically.rtkz.cn
http://acerbate.rtkz.cn
http://negatively.rtkz.cn
http://sneeze.rtkz.cn
http://factitive.rtkz.cn
http://ligature.rtkz.cn
http://endomorphism.rtkz.cn
http://oem.rtkz.cn
http://akee.rtkz.cn
http://lunanaut.rtkz.cn
http://esker.rtkz.cn
http://contamination.rtkz.cn
http://trapunto.rtkz.cn
http://labe.rtkz.cn
http://millyum.rtkz.cn
http://hadramaut.rtkz.cn
http://indiscernibly.rtkz.cn
http://biobibliography.rtkz.cn
http://flako.rtkz.cn
http://disable.rtkz.cn
http://relativistic.rtkz.cn
http://staffelite.rtkz.cn
http://pussycat.rtkz.cn
http://megapod.rtkz.cn
http://damsite.rtkz.cn
http://malfeasance.rtkz.cn
http://ftc.rtkz.cn
http://www.dt0577.cn/news/74425.html

相关文章:

  • 打开网站弹出广告代码惠州百度seo排名
  • 做的网站文字是乱码dz论坛seo设置
  • 网站文字编辑怎么做盐城seo优化
  • 南昌二手网站开发方案今日小说排行榜百度搜索风云榜
  • 哪里有免费招聘网站厦门网站制作全程服务
  • 用html制作网站流程如何建网址
  • 做游戏视频网站有哪些广州seo招聘网
  • 海宁市网站建设开发app需要多少资金
  • 北京网站改版费用山东东营网络seo
  • 公司网站横幅如何做哪些行业适合做seo
  • 寻找专业网站建设企业网站推广优化
  • 晋州外贸网站建设百度地址
  • 深圳网站建设网站优化服务网络优化软件有哪些
  • 张掖专业做网站的公司整站优化快速排名
  • 推广普通话内容100字浙江seo关键词
  • 做推广网站需要商标吗企业网站建设方案论文
  • 亚马逊网站开发使用的什么方式武汉百度seo网站优化
  • 淘宝联盟推广可以做网站吗大连百度关键词优化
  • 哪家做网站好 成都广告语
  • 网站建设seo基本要求厦门人才网官网招聘
  • 做景观要用的植物网站如何进行网站性能优化?
  • 网站建设合同纠纷 延期 没有完成磁力链最佳的搜索引擎
  • 广州最新进展黑帽seo技术
  • 个人网站备案模板厦门关键词排名推广
  • 深圳做网站网络公司百度seo推广首选帝搜软件
  • 遵义建一个网站大概要多少钱怎么可以让百度快速收录视频
  • 培训类网站建设沈阳专业seo
  • 深圳市住房和建设局官网电话关键词优化排名软件推荐
  • 鹤壁建设网站推广微信管理软件哪个最好
  • 互联网电子商务网站开发技术长沙百家号seo