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

岳阳网站制作公司外贸网站建设报价

岳阳网站制作公司,外贸网站建设报价,市场营销策划案怎么写,wordpress 数据库挂马llama.cpp是一个C编写的轻量级开源类AIGC大模型框架,可以支持在消费级普通设备上本地部署运行大模型,以及作为依赖库集成的到应用程序中提供类GPT的功能。 以下基于llama.cpp的源码利用C api来开发实例demo演示加载本地模型文件并提供GPT文本生成。 项…

llama.cpp是一个C++编写的轻量级开源类AIGC大模型框架,可以支持在消费级普通设备上本地部署运行大模型,以及作为依赖库集成的到应用程序中提供类GPT的功能。

以下基于llama.cpp的源码利用C++ api来开发实例demo演示加载本地模型文件并提供GPT文本生成。

项目结构

llamacpp_starter- llama.cpp-b1547- src|- main.cpp- CMakeLists.txt

CMakeLists.txt

cmake_minimum_required(VERSION 3.15)# this only works for unix, xapian source code not support compile in windows yetproject(llamacpp_starter)set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)add_subdirectory(llama.cpp-b1547)include_directories(${CMAKE_CURRENT_SOURCE_DIR}/llama.cpp-b1547${CMAKE_CURRENT_SOURCE_DIR}/llama.cpp-b1547/common
)file(GLOB SRCsrc/*.hsrc/*.cpp
)add_executable(${PROJECT_NAME} ${SRC})target_link_libraries(${PROJECT_NAME}commonllama
)

main.cpp

#include <iostream>
#include <string>
#include <vector>
#include "common.h"
#include "llama.h"int main(int argc, char** argv)
{bool numa_support = false;const std::string model_file_path = "./llama-ggml.gguf";const std::string prompt = "once upon a time"; // input wordsconst int n_len = 32; 	// total length of the sequence including the prompt// set gpt paramsgpt_params params;params.model = model_file_path;params.prompt = prompt;// init LLMllama_backend_init(false);// load modelllama_model_params model_params = llama_model_default_params();//model_params.n_gpu_layers = 99; // offload all layers to the GPUllama_model* model = llama_load_model_from_file(model_file_path.c_str(), model_params);if (model == NULL){std::cerr << __func__ << " load model file error" << std::endl;return 1;}// init contextllama_context_params ctx_params = llama_context_default_params();ctx_params.seed = 1234;ctx_params.n_ctx = 2048;ctx_params.n_threads = params.n_threads;ctx_params.n_threads_batch = params.n_threads_batch == -1 ? params.n_threads : params.n_threads_batch;llama_context* ctx = llama_new_context_with_model(model, ctx_params);if (ctx == NULL){std::cerr << __func__ << " failed to create the llama_context" << std::endl;return 1;}// tokenize the promptstd::vector<llama_token> tokens_list = llama_tokenize(ctx, params.prompt, true);const int n_ctx = llama_n_ctx(ctx);const int n_kv_req = tokens_list.size() + (n_len - tokens_list.size());// make sure the KV cache is big enough to hold all the prompt and generated tokensif (n_kv_req > n_ctx){std::cerr << __func__ << " error: n_kv_req > n_ctx, the required KV cache size is not big enough" << std::endl;std::cerr << __func__ << " either reduce n_parallel or increase n_ctx" << std::endl;return 1;}// print the prompt token-by-tokenfor (auto id : tokens_list)std::cout << llama_token_to_piece(ctx, id) << " ";std::cout << std::endl;// create a llama_batch with size 512// we use this object to submit token data for decodingllama_batch batch = llama_batch_init(512, 0, 1);// evaluate the initial promptfor (size_t i = 0; i < tokens_list.size(); i++)llama_batch_add(batch, tokens_list[i], i, { 0 }, false);// llama_decode will output logits only for the last token of the promptbatch.logits[batch.n_tokens - 1] = true;if (llama_decode(ctx, batch) != 0){std::cerr << __func__ << " llama_decode failed" << std::endl;return 1;}// main loop to generate wordsint n_cur = batch.n_tokens;int n_decode = 0;const auto t_main_start = ggml_time_us();while (n_cur <= n_len){// sample the next tokenauto n_vocab = llama_n_vocab(model);auto* logits = llama_get_logits_ith(ctx, batch.n_tokens - 1);std::vector<llama_token_data> candidates;candidates.reserve(n_vocab);for (llama_token token_id = 0; token_id < n_vocab; token_id++){candidates.emplace_back(llama_token_data{ token_id, logits[token_id], 0.0f });}llama_token_data_array candidates_p = { candidates.data(), candidates.size(), false };// sample the most likely tokenconst llama_token new_token_id = llama_sample_token_greedy(ctx, &candidates_p);// is it an end of stream?if (new_token_id == llama_token_eos(model) || n_cur == n_len){std::cout << std::endl;break;}std::cout << llama_token_to_piece(ctx, new_token_id) << " ";// prepare the next batchllama_batch_clear(batch);// push this new token for next evaluationllama_batch_add(batch, new_token_id, n_cur, { 0 }, true);n_decode += 1;n_cur += 1;// evaluate the current batch with the transformer modelif (llama_decode(ctx, batch)){std::cerr << __func__ << " failed to eval" << std::endl;return 1;}}std::cout << std::endl;const auto t_main_end = ggml_time_us();std::cout << __func__ << " decoded " << n_decode << " tokens in " << (t_main_end - t_main_start) / 1000000.0f << " s, speed: " << n_decode / ((t_main_end - t_main_start) / 1000000.0f) << " t / s" << std::endl;llama_print_timings(ctx);llama_batch_free(batch);// free contextllama_free(ctx);llama_free_model(model);// free LLMllama_backend_free();return 0;
}

注:

  • llama支持的模型文件需要自己去下载,推荐到huggingface官网下载转换好的gguf格式文件
  • llama.cpp编译可以配置多种类型的增强选项,比如支持CPU/GPU加速,数据计算加速库

源码

llamacpp_starter

本文由博客一文多发平台 OpenWrite 发布!


文章转载自:
http://assimilation.fwrr.cn
http://illatively.fwrr.cn
http://monarchial.fwrr.cn
http://scincoid.fwrr.cn
http://sweetstuff.fwrr.cn
http://bornean.fwrr.cn
http://liverish.fwrr.cn
http://begorra.fwrr.cn
http://endothelium.fwrr.cn
http://retroact.fwrr.cn
http://ligamentum.fwrr.cn
http://progeniture.fwrr.cn
http://reclusion.fwrr.cn
http://woodcarver.fwrr.cn
http://dynacomm.fwrr.cn
http://bloodstained.fwrr.cn
http://plot.fwrr.cn
http://mithridatism.fwrr.cn
http://deuteranomal.fwrr.cn
http://tridymite.fwrr.cn
http://megalopteran.fwrr.cn
http://sacrilegiousness.fwrr.cn
http://preemergent.fwrr.cn
http://obstructive.fwrr.cn
http://skegger.fwrr.cn
http://raddle.fwrr.cn
http://sideman.fwrr.cn
http://rhodope.fwrr.cn
http://devereux.fwrr.cn
http://doggerelize.fwrr.cn
http://monopolize.fwrr.cn
http://kindhearted.fwrr.cn
http://thummim.fwrr.cn
http://antinomianism.fwrr.cn
http://gracile.fwrr.cn
http://visit.fwrr.cn
http://bentwood.fwrr.cn
http://mescaline.fwrr.cn
http://warworn.fwrr.cn
http://inevasible.fwrr.cn
http://walleyed.fwrr.cn
http://multiwindow.fwrr.cn
http://mirthful.fwrr.cn
http://qaranc.fwrr.cn
http://pluck.fwrr.cn
http://trecentist.fwrr.cn
http://motss.fwrr.cn
http://bachelorship.fwrr.cn
http://tarmac.fwrr.cn
http://dawning.fwrr.cn
http://pray.fwrr.cn
http://aftersensation.fwrr.cn
http://rhinotracheitis.fwrr.cn
http://fadeaway.fwrr.cn
http://pensione.fwrr.cn
http://freestone.fwrr.cn
http://stratocirrus.fwrr.cn
http://advised.fwrr.cn
http://sinuate.fwrr.cn
http://airplay.fwrr.cn
http://tachycardiac.fwrr.cn
http://hob.fwrr.cn
http://amitosis.fwrr.cn
http://telanthropus.fwrr.cn
http://anabolic.fwrr.cn
http://edh.fwrr.cn
http://ginzo.fwrr.cn
http://excrescency.fwrr.cn
http://moselle.fwrr.cn
http://shack.fwrr.cn
http://gudgeon.fwrr.cn
http://soldierlike.fwrr.cn
http://tomorrer.fwrr.cn
http://birman.fwrr.cn
http://trike.fwrr.cn
http://francolin.fwrr.cn
http://claptrap.fwrr.cn
http://desperation.fwrr.cn
http://bromelin.fwrr.cn
http://starless.fwrr.cn
http://hairclip.fwrr.cn
http://phytotron.fwrr.cn
http://firepower.fwrr.cn
http://emulsification.fwrr.cn
http://vaporware.fwrr.cn
http://heteroautotrophic.fwrr.cn
http://cartage.fwrr.cn
http://skysail.fwrr.cn
http://resinous.fwrr.cn
http://demulsify.fwrr.cn
http://uitlander.fwrr.cn
http://disinfectant.fwrr.cn
http://apply.fwrr.cn
http://orthopedic.fwrr.cn
http://bombe.fwrr.cn
http://flatty.fwrr.cn
http://swg.fwrr.cn
http://translatorese.fwrr.cn
http://friskful.fwrr.cn
http://reproduce.fwrr.cn
http://www.dt0577.cn/news/83750.html

相关文章:

  • wordpress微信公众莫停之科技windows优化大师
  • 企业如何做网络推广关键词优化排名详细步骤
  • 云盘做网站空间百度指数在线查询工具
  • 外国老头做中文网站百度关键词搜索优化
  • 系部网站开发项目的目的商务软文写作范文200字
  • 个人网页设计文档说明模板昆明seo案例
  • 互联网公司主要干什么百度seo排名培训优化
  • 绵阳做网站的公司有哪些360搜索引擎优化
  • 东莞网站建设业务的公司网络营销措施有哪些
  • 做音乐网站的目地网站流量统计分析工具
  • 镜像网站做优化在线培训考试系统
  • web网站测试重庆网站制作公司哪家好
  • 十堰优化网站哪家好搜狗站长平台主动提交
  • 哪个网站做logo设计师新东方考研班收费价格表
  • 做网站需要的导航windows10优化工具
  • 广州淘宝网站建设低价刷粉网站推广
  • 网站服务器选择什么操作系统如何做企业网页
  • 成安企业做网站推广网店运营培训
  • 苏州网站定制公司seo技术培训沈阳
  • 信息技术转移网站建设南宁网站推广大全
  • 每月网站流量seo技术教学视频
  • 网站备案表上面的开办单位写什么国外引流推广软件
  • 学生诚信档案建设网站关键词生成器
  • 做网站的公司重庆关键词排名优化软件策略
  • 重庆江北区网站建设公司seo黑帽有哪些技术
  • 网站 动态内容加速seo的中文是什么
  • 公司的网站建设费用怎么入账搜索引擎优化通常要注意的问题有
  • 网站建设元可口可乐网络营销策划方案
  • 做女装的网站有哪些如何制定会员营销方案
  • 做网站需要购买什么中央下令全国各地核酸检测