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

大模型学习五:‌DeepSeek Janus-Pro-7B 多模态半精度本地部署指南:环境是腾讯cloudstudio高性能GPU 16G免费算力

一、说明介绍

由于前面玩过了,所以啥也别说,就是显存不够玩,要优化,没钱就是这么回事,看下图,显存实际只有15360M,确实是16G+

如何获取算力

 

二、如何获取算力

1、进入网址 Cloud Studio

2、没有注册的注册

应该是可以和腾讯云共账号,忘了

3、选择 Ai模板

看到高性能没有,这个有GPU 

也可以进入高性能工作空间

注意那个立即创建是cpu的,我们要点新建,可以创建很多个,同时工作的可以有两个,总共每月10000分钟,最开始50000分钟,之所以选这个高性能工作空间,这里一般的硬盘比较小,这个比较大,下图中的Pytorch2.0.0 只有30G左右,不够用,其它的有时间可以进去看看,选择deepseek-R1的环境,可以用OLlama直接部署几个蒸馏模型,试了下,14b的可以部署,再往上GPU就不够了

三、部署与测试

前面几篇文章其实已经部署过了,这篇文章其实是优化,

1、创建新的工作空间

我们建立了新的环境,今天还是很快的,一般要几分钟。反正不需要可以删除,放着也行,随时可以创建,最近几天放假,很好创建,前几天进都进不去,直接显示算力没有。这个有点不好的就是好像不能写描述,最开始可以的,不知道从哪里进去建立可以,反正这个方法建立时没有地方修改,大家弄个表格记录下,以后都忘了哪个工作空间是干嘛。

已经完成,有运行中,直接点击这一排,就可以进去,

代码可以放在下图的workspace里,和VScode差不多, 

 

如下图,点击上面的终端,新建终端,就显示终端了

2、下载源码 

cd /workspace
git clone https://github.com/deepseek-ai/Janus.git
#难道关税大战,github也要干掉了,有点怀疑啊,慢的要死,我是直接上传,clone不成功
cd Janus

3、安装Python环境

# ubuntu环境
apt-get update
apt-get install build-essential
apt-get install cmake
apt-get install pkg-configconda create -n janus python=3.10
conda init
source ~/.bashrc
conda activate janus
cd /workspace/Janus
# 注意后面的点
pip install -e .[gradio]
pip install bitsandbytes accelerate flash-attn

 4、显存优化的方法

- 确保模型以4-bit或8-bit加载。

- 使用半精度(torch.float16)。

- 启用Flash Attention。

- 调整batch size为1,避免处理多个样本。

- 使用内存优化库如vLLM或Hugging Face的优化选项(如device_map="auto",可能结合offload_folder等参数)。

- 如果使用文本生成,限制生成的最大长度和min_length,减少显存占用。

5、下载模型 

这里我们考虑在项目主目录下创建models文件夹,用于保存Janus-Pro-1B和7B模型权重。考虑到国 内网络环境,这里推荐直接在Modelscope上进行模型权重下载。

Janus-Pro-1B模型权重: 魔搭社区 Janus-Pro-7B模型权重: 魔搭社区

  • 安装modelscope 
pip install modelscope
  • 创建模型文件夹

我们这次创建在demo文件夹下面


mkdir -p demo/Janus-Pro-7B
# 进入app_januspro.py的目录
cd demo
# 下载7B模型
modelscope download --model deepseek-ai/Janus-Pro-7B --local_dir ./Janus-Pro-7B

下载需要点时间,看网速,一般还是比较快的。 

 

6、修改app_januspro.py

下载frpc_linux_amd64并放在合适的地方,没有配置时会提示错误,最新版gradio会提示0.3版本

我用的是0.2,也就是requirements.txt表明了gradio==3.48.0

运行之前 
下载地址:https://download.csdn.net/download/jiangkp/90568217
mv frpc_linux_amd64_v0.2 /root/miniforge3/envs/janus/lib/python3.10/site-packages/gradio
chmod +x /root/miniforge3/envs/janus/lib/python3.10/site-packages/gradio/frpc_linux_amd64_v0.2

一些优化设置关键点我在代码里注释了

代码如下;

import gradio as gr
import torch
from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from janus.models import MultiModalityCausalLM, VLChatProcessor
from janus.utils.io import load_pil_images
from PIL import Imageimport numpy as np
import os
import time
# import spaces  # Import spaces for ZeroGPU compatibility
#4-bit量化:
#通过BitsAndBytesConfig启用4位量化,显存需求降至原大小的1/4
#双重量化进一步压缩参数
#半精度计算:torch.float16减少计算过程中的内存占用
#Flash Attention:加速注意力计算,降低内存峰值#设备自动映射:device_map="auto"自动优化跨设备分布(适合多卡环境)# 配置4-bit量化,添加代码
bnb_config = BitsAndBytesConfig(load_in_4bit=True,bnb_4bit_use_double_quant=True,bnb_4bit_quant_type="nf4",bnb_4bit_compute_dtype=torch.float16
)
# Load model and processor
model_path = "/workspace/Janus/demo/Janus-Pro-7B"
config = AutoConfig.from_pretrained(model_path)
language_config = config.language_config
language_config._attn_implementation = 'eager'
vl_gpt = AutoModelForCausalLM.from_pretrained(model_path,quantization_config=bnb_config,device_map="auto",language_config=language_config,trust_remote_code=True,torch_dtype=torch.float16#,attn_implementation="flash_attention_2"  # 启用Flash Attention)
#if torch.cuda.is_available():
#    vl_gpt = vl_gpt.to(torch.bfloat16).cuda()
#else:
#    vl_gpt = vl_gpt.to(torch.float16)vl_chat_processor = VLChatProcessor.from_pretrained(model_path)
tokenizer = vl_chat_processor.tokenizer
cuda_device = 'cuda' if torch.cuda.is_available() else 'cpu'@torch.inference_mode()
# @spaces.GPU(duration=120) 
# Multimodal Understanding function
def multimodal_understanding(image, question, seed, top_p, temperature):# Clear CUDA cache before generatingtorch.cuda.empty_cache()# set seedtorch.manual_seed(seed)np.random.seed(seed)torch.cuda.manual_seed(seed)conversation = [{"role": "<|User|>","content": f"<image_placeholder>\n{question}","images": [image],},{"role": "<|Assistant|>", "content": ""},]pil_images = [Image.fromarray(image)]prepare_inputs = vl_chat_processor(conversations=conversation, images=pil_images, force_batchify=True).to(cuda_device, dtype=torch.float16)inputs_embeds = vl_gpt.prepare_inputs_embeds(**prepare_inputs)outputs = vl_gpt.language_model.generate(inputs_embeds=inputs_embeds,attention_mask=prepare_inputs.attention_mask,pad_token_id=tokenizer.eos_token_id,bos_token_id=tokenizer.bos_token_id,eos_token_id=tokenizer.eos_token_id,max_new_tokens=512,do_sample=False if temperature == 0 else True,use_cache=True,temperature=temperature,top_p=top_p,)answer = tokenizer.decode(outputs[0].cpu().tolist(), skip_special_tokens=True)return answerdef generate(input_ids,width,height,temperature: float = 1,parallel_size: int = 5,cfg_weight: float = 5,image_token_num_per_image: int = 576,patch_size: int = 16):# Clear CUDA cache before generatingtorch.cuda.empty_cache()tokens = torch.zeros((parallel_size * 2, len(input_ids)), dtype=torch.int).to(cuda_device)for i in range(parallel_size * 2):tokens[i, :] = input_idsif i % 2 != 0:tokens[i, 1:-1] = vl_chat_processor.pad_idinputs_embeds = vl_gpt.language_model.get_input_embeddings()(tokens)generated_tokens = torch.zeros((parallel_size, image_token_num_per_image), dtype=torch.int).to(cuda_device)pkv = Nonefor i in range(image_token_num_per_image):with torch.no_grad():outputs = vl_gpt.language_model.model(inputs_embeds=inputs_embeds,use_cache=True,past_key_values=pkv)pkv = outputs.past_key_valueshidden_states = outputs.last_hidden_statelogits = vl_gpt.gen_head(hidden_states[:, -1, :])logit_cond = logits[0::2, :]logit_uncond = logits[1::2, :]logits = logit_uncond + cfg_weight * (logit_cond - logit_uncond)probs = torch.softmax(logits / temperature, dim=-1)next_token = torch.multinomial(probs, num_samples=1)generated_tokens[:, i] = next_token.squeeze(dim=-1)next_token = torch.cat([next_token.unsqueeze(dim=1), next_token.unsqueeze(dim=1)], dim=1).view(-1)img_embeds = vl_gpt.prepare_gen_img_embeds(next_token)inputs_embeds = img_embeds.unsqueeze(dim=1)#添加下面一行,强制转回为torch.bfloat16vl_gpt.gen_vision_model = vl_gpt.gen_vision_model.to(dtype=torch.bfloat16)patches = vl_gpt.gen_vision_model.decode_code(generated_tokens.to(dtype=torch.int),shape=[parallel_size, 8, width // patch_size, height // patch_size])return generated_tokens.to(dtype=torch.int), patchesdef unpack(dec, width, height, parallel_size=5):dec = dec.to(torch.float32).cpu().numpy().transpose(0, 2, 3, 1)dec = np.clip((dec + 1) / 2 * 255, 0, 255)visual_img = np.zeros((parallel_size, width, height, 3), dtype=np.uint8)visual_img[:, :, :] = decreturn visual_img@torch.inference_mode()
# @spaces.GPU(duration=120)  # Specify a duration to avoid timeout
def generate_image(prompt,seed=None,guidance=5,t2i_temperature=1.0):# Clear CUDA cache and avoid tracking gradientstorch.cuda.empty_cache()# Set the seed for reproducible resultsif seed is not None:torch.manual_seed(seed)torch.cuda.manual_seed(seed)np.random.seed(seed)width = 384height = 384# 这个改为1 每次生成一张图片parallel_size = 1with torch.no_grad():messages = [{'role': '<|User|>', 'content': prompt},{'role': '<|Assistant|>', 'content': ''}]text = vl_chat_processor.apply_sft_template_for_multi_turn_prompts(conversations=messages,sft_format=vl_chat_processor.sft_format,system_prompt='')text = text + vl_chat_processor.image_start_taginput_ids = torch.LongTensor(tokenizer.encode(text))output, patches = generate(input_ids,width // 16 * 16,height // 16 * 16,cfg_weight=guidance,parallel_size=parallel_size,temperature=t2i_temperature)images = unpack(patches,width // 16 * 16,height // 16 * 16,parallel_size=parallel_size)return [Image.fromarray(images[i]).resize((768, 768), Image.LANCZOS) for i in range(parallel_size)]# Gradio interface
with gr.Blocks() as demo:# gr.Markdown(value="# Multimodal Understanding")with gr.Tabs():# 多模态理解标签页with gr.Tab("Multimodal Understanding/多模态理解"):with gr.Row():image_input = gr.Image()with gr.Column():question_input = gr.Textbox(label="Question/你的问题")und_seed_input = gr.Number(label="Seed/随机种子", precision=0, value=42)top_p = gr.Slider(minimum=0, maximum=1, value=0.95, step=0.05, label="top_p/核采样")temperature = gr.Slider(minimum=0, maximum=1, value=0.1, step=0.05, label="temperature/置信度")understanding_button = gr.Button("Chat/开始交互")understanding_output = gr.Textbox(label="Response/回答")understanding_button.click(multimodal_understanding,inputs=[image_input, question_input, und_seed_input, top_p, temperature],outputs=understanding_output)examples_inpainting = gr.Examples(label="Multimodal Understanding examples/多模态理解例子",examples=[["explain this meme/解释这个图片","images/doge.png",],["Convert the formula into latex code./ 公式转换为latex格式.","images/equation.png",],],inputs=[question_input, image_input],)# gr.Markdown(value="# Text-to-Image Generation")# 文生图标签页with gr.Tab("Text-to-Image Generation/文生图"):with gr.Row():cfg_weight_input = gr.Slider(minimum=1, maximum=10, value=5, step=0.5, label="CFG Weight/CFG的权重")t2i_temperature = gr.Slider(minimum=0, maximum=1, value=1.0, step=0.05, label="temperature/置信度")prompt_input = gr.Textbox(label="Prompt. (Prompt in more detail can help produce better images!)/提示语")seed_input = gr.Number(label="Seed (Optional)/随机种子(可选)", precision=0, value=12345)generation_button = gr.Button("Generate Images/生成图片")image_output = gr.Gallery(label="Generated Images/生成图片", columns=2, rows=2, height=300)generation_button.click(fn=generate_image,inputs=[prompt_input, seed_input, cfg_weight_input, t2i_temperature],outputs=image_output)examples_t2i = gr.Examples(label="Text to image generation examples./文本到图片",examples=["Master shifu racoon wearing drip attire as a street gangster.","The face of a beautiful girl","Astronaut in a jungle, cold color palette, muted colors, detailed, 8k","A glass of red wine on a reflective surface.","A cute and adorable baby fox with big brown eyes, autumn leaves in the background enchanting,immortal,fluffy, shiny mane,Petals,fairyism,unreal engine 5 and Octane Render,highly detailed, photorealistic, cinematic, natural colors.","The image features an intricately designed eye set against a circular backdrop adorned with ornate swirl patterns that evoke both realism and surrealism. At the center of attention is a strikingly vivid blue iris surrounded by delicate veins radiating outward from the pupil to create depth and intensity. The eyelashes are long and dark, casting subtle shadows on the skin around them which appears smooth yet slightly textured as if aged or weathered over time.\n\nAbove the eye, there's a stone-like structure resembling part of classical architecture, adding layers of mystery and timeless elegance to the composition. This architectural element contrasts sharply but harmoniously with the organic curves surrounding it. Below the eye lies another decorative motif reminiscent of baroque artistry, further enhancing the overall sense of eternity encapsulated within each meticulously crafted detail. \n\nOverall, the atmosphere exudes a mysterious aura intertwined seamlessly with elements suggesting timelessness, achieved through the juxtaposition of realistic textures and surreal artistic flourishes. Each component\u2014from the intricate designs framing the eye to the ancient-looking stone piece above\u2014contributes uniquely towards creating a visually captivating tableau imbued with enigmatic allure.",],inputs=prompt_input,)  demo.launch(share=True)
# demo.queue(concurrency_count=1, max_size=10).launch(server_name="0.0.0.0", server_port=37906, root_path="/path")

 7、运行

python demo/app_januspro.py

8、结果

Running on local URL:  http://127.0.0.1:7860
IMPORTANT: You are using gradio version 3.48.0, however version 4.44.1 is available, please upgrade.
--------
Running on public URL: https://edd2f234a885706e90.gradio.live

This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)
 

 http://127.0.0.1:7860:本地可以用这个地址测试

gradio version 3.48.0, however version 4.44.1:如果你升级了,就会有问题,frpc_linux_amd64需要升级到0.3,我用的0.2

https://edd2f234a885706e90.gradio.live:这个是穿透后的公网地址,只能保持72小时,这个地址运行一次就改变一次

运行后初始

9、多模态理解测试

测试一

英文问结果

中文问结果: 

 

对比下,自己看看喔

 测试二

中国人直接中文问

测试三

个人感觉不太好,不准啊,不知道不用4bit的会不会好点 

10、 文生图测试

测试一

挂了

This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)
Traceback (most recent call last):
  File "/root/miniforge3/envs/janus/lib/python3.10/site-packages/gradio/routes.py", line 534, in predict
    output = await route_utils.call_process_api(
  File "/root/miniforge3/envs/janus/lib/python3.10/site-packages/gradio/route_utils.py", line 226, in call_process_api
    output = await app.get_blocks().process_api(
  File "/root/miniforge3/envs/janus/lib/python3.10/site-packages/gradio/blocks.py", line 1550, in process_api
    result = await self.call_function(
  File "/root/miniforge3/envs/janus/lib/python3.10/site-packages/gradio/blocks.py", line 1185, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "/root/miniforge3/envs/janus/lib/python3.10/site-packages/anyio/to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
  File "/root/miniforge3/envs/janus/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 2470, in run_sync_in_worker_thread
    return await future
  File "/root/miniforge3/envs/janus/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 967, in run
    result = context.run(func, *args)
  File "/root/miniforge3/envs/janus/lib/python3.10/site-packages/gradio/utils.py", line 661, in wrapper
    response = f(*args, **kwargs)
  File "/root/miniforge3/envs/janus/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context
    return func(*args, **kwargs)
  File "/workspace/Janus/demo/app_januspro.py", line 179, in generate_image
    output, patches = generate(input_ids,
  File "/workspace/Janus/demo/app_januspro.py", line 136, in generate
    patches = vl_gpt.gen_vision_model.decode_code(generated_tokens.to(dtype=torch.int),
  File "/workspace/Janus/janus/models/vq_model.py", line 507, in decode_code
    dec = self.decode(quant_b)
  File "/workspace/Janus/janus/models/vq_model.py", line 502, in decode
    dec = self.decoder(quant)
  File "/root/miniforge3/envs/janus/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1739, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/root/miniforge3/envs/janus/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1750, in _call_impl
    return forward_call(*args, **kwargs)
  File "/workspace/Janus/janus/models/vq_model.py", line 208, in forward
    h = block.upsample(h)
  File "/root/miniforge3/envs/janus/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1739, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/root/miniforge3/envs/janus/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1750, in _call_impl
    return forward_call(*args, **kwargs)
  File "/workspace/Janus/janus/models/vq_model.py", line 426, in forward
    x = self.conv(x)
  File "/root/miniforge3/envs/janus/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1739, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/root/miniforge3/envs/janus/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1750, in _call_impl
    return forward_call(*args, **kwargs)
  File "/root/miniforge3/envs/janus/lib/python3.10/site-packages/torch/nn/modules/conv.py", line 554, in forward
    return self._conv_forward(input, self.weight, self.bias)
  File "/root/miniforge3/envs/janus/lib/python3.10/site-packages/torch/nn/modules/conv.py", line 549, in _conv_forward
    return F.conv2d(
RuntimeError: Input type (c10::BFloat16) and bias type (c10::Half) should be the same

 #添加下面一行,强制转回为torch.bfloat16vl_gpt.gen_vision_model = vl_gpt.gen_vision_model.to(dtype=torch.bfloat16)patches = vl_gpt.gen_vision_model.decode_code(generated_tokens.to(dtype=torch.int),shape=[parallel_size, 8, width // patch_size, height // patch_size])

一直504 (Gateway Timeout),同志们。后来我就更新了gradio

# 更新
pip install -U gradio# 上传frpc_linux_amd64_v0.3,前面有下载地址
mv frpc_linux_amd64_v0.3 /root/miniforge3/envs/janus/lib/python3.10/site-packages/gradio
chmod +x /root/miniforge3/envs/janus/lib/python3.10/site-packages/gradio/frpc_linux_amd64_v0.3

执行

# 设置了超时,个人感觉旧版的GRADIO,这个超时设置无效
GRADIO_SERVER_TIMEOUT=300 python demo/app_januspro.py

测试二

相关文章:

大模型学习五:‌DeepSeek Janus-Pro-7B 多模态半精度本地部署指南:环境是腾讯cloudstudio高性能GPU 16G免费算力

一、说明介绍 由于前面玩过了&#xff0c;所以啥也别说&#xff0c;就是显存不够玩&#xff0c;要优化&#xff0c;没钱就是这么回事&#xff0c;看下图&#xff0c;显存实际只有15360M&#xff0c;确实是16G 如何获取算力 二、如何获取算力 1、进入网址 Cloud Studio 2、没有…...

Spring 中的事务

&#x1f9fe; 一、什么是事务&#xff1f; &#x1f9e0; 通俗理解&#xff1a; 事务 一组操作&#xff0c;要么全部成功&#xff0c;要么全部失败&#xff0c;不能只做一半。 比如你转账&#xff1a; A 账户扣钱B 账户加钱 如果 A 扣了钱但 B 没收到&#xff0c;那就出问…...

2025-04-06 NO.2 Quest3 基础配置与打包

文章目录 1 场景配置1.1 开启手势支持1.2 创建 OVRCameraRig1.3 创建可交互 Cube 2 打包配置 环境&#xff1a; Windows 11Unity6000.0.42f1 Quest3 开发环境配置见 2025-03-17 NO.1 Quest3 开发环境配置教程_quest3 unity 开发流程-CSDN博客。 1 场景配置 1.1 开启手势支持 …...

人脸考勤管理一体化系统(人脸识别系统,签到打卡)

人脸考勤管理一体化系统 项目介绍 本项目是基于Flask、SQLAlchemy、face_recognition库的人脸考勤管理一体化系统。 系统通过人脸识别技术实现员工考勤打卡、人脸信息采集、人脸模型训练等功能。 项目采用前后端分离的技术框架&#xff0c;基于Flask轻量级Web框架搭建后端服务…...

LeetCode 每日一题 2025/3/31-2025/4/6

记录了初步解题思路 以及本地实现代码&#xff1b;并不一定为最优 也希望大家能一起探讨 一起进步 目录 3/31 2278. 字母在字符串中的百分比4/1 2140. 解决智力问题4/2 2873. 有序三元组中的最大值 I4/3 2874. 有序三元组中的最大值 II4/4 1123. 最深叶节点的最近公共祖先4/5 1…...

mybatis plus 实体类基于视图,更新单表的时候报视图或函数‘v_视图名‘不可更新,因为修改会影响多个基表的错误的简单处理方法。

1、之前的文章中写了一下基于视图的实体&#xff0c;因为当前测试通过了&#xff0c;可能有缓存。 2、然后今天又用到了这个方法&#xff0c;发现报错了&#xff1a; 建了一下视图&#xff0c;将实体类绑定到了视图中&#xff0c;并不是原表中。 3、用mybatis提供的注解或者x…...

语法: i8=make8( var, offset);

MAKE8( ) 语法: i8make8( var, offset); 参数: var是16位或32位整数; offset是字节的偏移量,为1,2或3; 返回值: 返回值是一个8位整数; 功能: 该函数用来摘取以var为基址, offset为偏移量,所指向单元的字节;除了执行单字节复制之外,还相当于i8( ( var>>(offset…...

Seata TCC模式是怎么实现的?

Seata TCC 模式实现原理 TCC(Try-Confirm-Cancel)是 Seata 提供的分布式事务解决方案之一,适用于 高并发、高性能 场景,通过 业务补偿 保证最终一致性。其核心思想是将事务拆分为三个阶段: Try:预留资源(冻结数据,检查约束)。Confirm:确认提交(真正扣减资源)。Can…...

sentinel新手入门安装和限流,热点的使用

1 sentinel入门 1.1下载sentinel控制台 &#x1f517;sentinel管理后台官方下载地址 下载完毕以后就会得到一个jar包 1.2启动sentinel 将jar包放到任意非中文目录&#xff0c;执行命令&#xff1a; java -jar 名字.jar如果要修改Sentinel的默认端口、账户、密码&#xff…...

对责任链模式的理解

对责任链模式的理解 一、场景1、题目【[来源](https://kamacoder.com/problempage.php?pid1100)】1.1 题目描述1.2 输入描述1.3 输出描述1.4 输入示例1.5 输出示例 二、不采用责任链模式1、代码2、缺点 三、采用责任链模式1、代码2、优点 四、思考 一、场景 1、题目【来源】 …...

AGI大模型(11):RAG系统

1 RAG概念 RAG(Retrieval Augmented Generation)顾名思义,通过检索外部数据,增强大模型的生成效果。 RAG即检索增强生成,为LLM提供了从某些数据源检索到的信息,并基于此修正生成的答案。RAG基本上是Search + LLM 提示,可以通过大模型回答查询,并将搜索算法所找到的信…...

请问你了解什么测试方法?

测试方法在软件测试中是保障软件质量的关键手段,我将从黑盒测试、白盒测试、灰盒测试等方面为你介绍常见的测试方法: 黑盒测试方法 黑盒测试把软件看作一个黑盒子,不考虑内部结构和实现细节,只关注输入和输出。 等价类划分法:将输入数据划分为有效等价类和无效等价类,从…...

【springcloud】快速搭建一套分布式服务springcloudalibaba(三)

第三篇 基于nacos搭建分布式项目 分布式事务&#xff08;分布式锁事务&#xff09; 项目所需 maven nacos java8 idea git mysql(下单) redis(分布式锁) 本文主要讲解客户下单时扣减库存的操作&#xff0c;网关系统/用户系统/商品系统/订单系统 请先准备好环境&#xff0…...

Nginx-keepalived-高可用

Nginx 高可用 通常 借助 Keepalived 实现&#xff0c; Keepalived 能通过 VRRP &#xff08;虚拟路由冗余协议&#xff09;让多个 Nginx 服务器 组成一个 热备集群&#xff0c;当主服务器故障时自动切换到备用服务器&#xff0c;保障服务不间断。 一、环境准备 角色IP 地址主…...

Linux系统管理(十九)——欧拉系统硬盘挂载、网络配置以及Docker环境安装

挂载硬盘 如果数据盘在安装操作系统的时候没有挂载&#xff0c;需要自己做一下硬盘的挂载 查看需要挂载硬盘的路径 fdisk -l这里的可挂载的硬盘路径为&#xff1a;/dev/sdb MBR分区方式转换成GPT MBR分区能挂载的硬盘空间有限&#xff0c;无法挂载全部硬盘空间&#xff0…...

vue记忆卡牌游戏

说明&#xff1a; 我希望用vue做一款记忆卡牌游戏 游戏规则如下&#xff1a; 游戏设置&#xff1a;使用3x4的网格&#xff0c;包含3对字母&#xff08;A,B,C,D,E,F&#xff09;。 ​随机洗牌&#xff1a;初始字母对被打乱顺序&#xff0c;生成随机布局。 ​游戏流程&#xff1a…...

LearnOpenGL-笔记-其九

今天让我们完结高级OpenGL的部分&#xff1a; Instancing 很多时候&#xff0c;在场景中包含有大量实例的时候&#xff0c;光是调用GPU的绘制函数这个过程都会带来非常大的开销&#xff0c;因此我们需要想办法在每一次调用GPU的绘制函数时尽可能多地绘制&#xff0c;这个过程就…...

开源软件与自由软件:一场理念与实践的交锋

在科技的世界里&#xff0c;“开源软件”和“自由软件”这两个词几乎无人不知。很多人或许都听说过&#xff0c;它们的代码是公开的&#xff0c;可以供所有人查看、修改和使用。然而&#xff0c;若要细究它们之间的区别&#xff0c;恐怕不少朋友会觉得云里雾里。今天&#xff0…...

关于使用HAL_ADC_Start函数时为什么要放在while里的解释

HAL_ADC_Start() 是一个用于启动 ADC&#xff08;模数转换器&#xff09;转换的函数&#xff0c;那为什么有时候我们会看到它被放在 while 循环里呢&#xff1f;其实取决于你使用的是哪种ADC采样方式&#xff0c;我们来细说&#x1f447;&#xff1a; &#x1f9e0; 一、先搞清…...

Qt 入门 2 之窗口部件 QWidget

Qt 入门2之窗口部件 QWidget Qt Creator 提供的默认基类只有QMainWindow、QWidget和QDialog 这3种&#xff0c;这3种窗体也是以后用得最多的&#xff0c;QMainWindow是带有菜单栏和工具栏的主窗口类,QDialog是各种对话框的基类,而它们全部继承自QWidget。不仅如此,其实所有的窗…...

在 Windows 上安装 WSL Ubuntu 的完整避坑指南:从报错到成功运行

问题背景​​ 最近在尝试通过 ​​Windows Subsystem for Linux (WSL)​​ 安装 Ubuntu 时&#xff0c;遇到了一系列报错。最初的步骤是直接使用 wsl --install 命令&#xff0c;但安装完成后发现系统中并未自动安装默认的 Ubuntu 发行版。随后尝试通过命令行手动选择发行版&a…...

STM32看门狗原理与应用详解:独立看门狗 vs 窗口看门狗(上) | 零基础入门STM32第九十四步

主题内容教学目的/扩展视频看门狗什么是看门狗&#xff0c;原理分析&#xff0c;启动喂狗方法&#xff0c;读标志位。熟悉在程序里用看门狗。 师从洋桃电子&#xff0c;杜洋老师 &#x1f4d1;文章目录 一、看门狗核心原理1.1 工作原理图解1.2 经典水桶比喻 二、STM32看门狗双雄…...

Hyperlane 框架路由功能详解:静态与动态路由全掌握

Hyperlane 框架路由功能详解&#xff1a;静态与动态路由全掌握 Hyperlane 框架提供了强大而灵活的路由功能&#xff0c;支持静态路由和动态路由两种模式&#xff0c;让开发者能够轻松构建各种复杂的 Web 应用。本文将详细介绍这两种路由的使用方法。 静态路由&#xff1a;简单…...

webpack js 逆向 --- 个人记录

网站 aHR0cDovL2FlcmZheWluZy5jb20v加密参数 参数加密位置 方法&#xff1a; 1. 构造自执行函数 !function(e) {// 加载器 }(// 模块1&#xff1b;// 模块2 )2. 找到js的加载器 3. 把上述代码放入第一步构造的自执行函数(完整扣取一整个加载器里的代码)&#xff0c;并用一…...

代码随想录回溯算法03

93.复原IP地址 本期本来是很有难度的&#xff0c;不过 大家做完 分割回文串 之后&#xff0c;本题就容易很多了 题目链接/文章讲解&#xff1a;代码随想录 视频讲解&#xff1a;回溯算法如何分割字符串并判断是合法IP&#xff1f;| LeetCode&#xff1a;93.复原IP地址_哔哩哔…...

SOMEIP通信矩阵解读

目录 1 摘要2 SOME/IP通信矩阵详细属性定义与示例2.1 服务基础属性2.2 数据类型定义2.3 服务实例与网络配置参数2.4 SOME/IP-SD Multicast 配置&#xff08;SOME/IP服务发现组播配置&#xff09;2.5 SOME/IP-SD Unicast 配置2.6 SOME/IP-SD ECU 配置参数详解 3 总结 1 摘要 本…...

keys简单通用命令

目录 一、通配符匹配key 二、key的常用命令 1&#xff09;exists 判断某个key是否存在 2&#xff09;删除key 3&#xff09;expire设置key的过期时间、ttl查询key的过期时间 4&#xff09;type可以获取key对应的value的类型 一、通配符匹配key redis作为键值对类型的数据…...

Linux : 页表

目录 一 前言 二 深入理解页表 三 页表的实际组成 四 总结 一 前言 页表是我们之前在讲到Linux : 进程地址空间-CSDN博客的时候说到的&#xff0c;它是物理内存到进程程序地址空间的一个桥梁&#xff0c;通过它&#xff0c;物理内存的数据和代码才能映射到进程的程序地址空间…...

多智能体优秀开发框架

原文链接:https://i68.ltd/notes/posts/20250402-multi-agent/ motia-面向软件工程师的智能体框架 项目仓库:https://github.com/MotiaDev/motia 1.3k官方网站:https://motia.devMotia 允许开发人员在几分钟内创建&#xff0c;测试和部署生产就绪的 AI 代理&#xff0c;在一个…...

JavaScript创建对象与构造函数

目录 创建对象 一、创建对象的 5 种核心方式 1. 对象字面量&#xff08;直接量&#xff09; 2. 使用 Object.create() 3. 工厂模式 4. 构造函数模式 5. ES6 class 语法&#xff08;语法糖&#xff09; 二、构造函数与 new 关键字 1. 构造函数的作用 2. 构造函数的特征…...

【langchain4j系列教程-02】Langchain4j调用DeepSeek

文章目录 依赖引入代码示例api key如何获取模型名称及价格为什么调用DeepSeek API用的是OpenAIChatModel 这篇文章主要介绍了如何在Java项目中引入DeepSeek的依赖&#xff0c;并提供了调用DeepSeek API的代码示例。 依赖引入 DeepSeek是一个与OpenAI接口标准兼容的人工智能平台…...

c++STL入门

目录 什么是STL&#xff1f; vector容器 构造函数 赋值操作 vector容量和大小 vector存放内置数据类型 vector存放自定义数据类型 存放指针 vector容器嵌套容器 string容器 构造函数 赋值操作 字符串拼接 查找和替换 string字符串比较 string字符存取 string插…...

公有云子账号认证的原理和步骤

1 为什么使用子账号 1.1 子账号认证的背景 主账号权限过大:公有云账号(主账号)对账号中的资源具有完全管理权限,且无法调整其权限大小,多人共用时无法在审计日志中区分出具体使用人,一旦泄露风险极大且难以追溯。 安全需求:为了提高安全性,避免因主账号信息泄露而导致…...

基于Flask的微博舆情数据分析系统

【Flask】基于Flask的微博舆情数据分析系统&#xff08;完整系统源码开发笔记详细部署教程&#xff09;✅ 目录 一、项目简介二、项目界面展示三、项目视频展示 一、项目简介 该系统能够高效收集、处理微博上的海量数据&#xff0c;实时反映公众对某些事件或话题的舆论倾向&am…...

Mac OS 禁用 SIP 系统完整性保护

关闭并重新启动 Mac&#xff0c;CommandR在启动时按住以进入Recovery Mode.进入Recovery模式后打开终端 -bash-3.2# csrutil disable Turning off System Integrity Protection reguires modifying system security.Allow booting unsigned operating systems and any ker…...

第十四届蓝桥杯省赛真题解析(含C++详细源码)

第十四届蓝桥杯省赛 整数删除满分思路及代码solution1 &#xff08;40% 双指针暴力枚举&#xff09;solution 2&#xff08;优先队列模拟链表 AC&#xff09; 冶炼金属满分代码及思路 子串简写满分思路及代码solution 1&#xff08;60% 双指针&#xff09;solution 2&#xff0…...

整车CAN网络和CANoe

车载网络中主要包含有Can网络,Lin网络,FlexRay,Most,以太网。 500kbps:500波特率,表示的数据传输的速度。表示的是最大的网速传输速度。也就是每秒 500kb BodyCan车身Can InfoCan娱乐信息Can 车身CAN主要连接的是ESB电动安全带 ADB自适应远光灯等 PTCan动力Can 底盘Can...

从扩展黎曼泽塔函数构造物质和时空的结构-16

都是一样的泽塔函数&#xff0c;却呈现出不同的性质&#xff0c;而不同的性质无关于自然数还是质数&#xff0c;完全是由s来决定的。可以猜想&#xff0c; 就是光子&#xff0c;而如果&#xff0c; 就是物质粒子。其中不同的k指出不同的周期或者对应于不同的质数p&#xff0c;虽…...

【C++】list模拟实现

&#x1f4dd;前言&#xff1a; 这篇文章我们来讲讲STL中list的模拟实现&#xff1a; &#x1f3ac;个人简介&#xff1a;努力学习ing &#x1f4cb;个人专栏&#xff1a;C学习笔记 &#x1f380;CSDN主页 愚润求学 &#x1f304;其他专栏&#xff1a;C语言入门基础&#xff0c…...

人脸专注度检测系统(课堂专注度检测、人脸检测、注意力检测系统)

人脸专注度检测系统 项目介绍 本项目是基于Flask、MobileNetV2、Mediapipe的人脸专注度检测系统。 项目采用tensorflow.keras库内置的MobileNetV2预训练模型&#xff0c;对自主采集的少量人脸图片数据迁移训练而得到最终的人脸专注度检测模型。 项目采用前后端分离的技术框架…...

文件操作和IO ——Java

初识文件 首先文件分为&#xff1a; 1.狭义的文件 – 保存在硬盘上的文件。 2.广义的文件 – 操作系统进行资源管理的一种机制。很多的软件/硬件资源&#xff0c;抽象成“文件”来进行表示。 &#xff08;println > 控制台&#xff0c;scanner > 控制台的标准输入&#…...

dmsetup 清理ceph osd残留磁盘分区

在物理机上接入磁盘并准备格式化时&#xff0c;发现磁盘中存在之前残留的 Ceph OSD 分区。尝试运用 fdisk 重新分区、重新格式化&#xff0c;以及使用 sgdisk 格式化&#xff0c;甚至重写磁盘头&#xff0c;都未能成功清理掉这些 OSD 残留分区。最终&#xff0c;借助 dmsetup 直…...

每日一题(小白)字符串娱乐篇16

分析题意可以了解到本题要求在一串字符串中找到所有组合起来排序递增的字符串。我们可以默认所有字符在字符串中的上升序列是1&#xff0c;从第一个字符开始找&#xff0c;如果后面的字符大于前面的字符就说明这是一个上序列那么后面字符所在的数组加一&#xff0c;如果连接不上…...

【Mac 从 0 到 1 保姆级配置教程 11】- Mac 基础配置 Finder、触控板、常用快捷键等

文章目录 前言配置 Finder1. 把我们的家目录请出来2. 显示文件扩展名3. 展示隐藏文件4. 显示路径栏和状态栏5. 固定文件夹到工具栏 基础快捷键1. Finder 导航快捷键2. 文件操作快捷键3. 视图和显示快捷键4. 搜索和选择快捷键5. 实用技巧6. 关于文件创建 配置触控板1. 右键设置2…...

Redis 渐进式rehash怎么判定rehash完成了?

Redis 渐进式 Rehash 的完成判断机制 在 Redis 的字典(dict)结构扩容或缩容时,会使用 渐进式 Rehash 来避免一次性迁移所有键值对导致的阻塞。以下是判断旧哈希表(ht[0])是否全部迁移完毕的核心逻辑: 1. 渐进式 Rehash 的核心流程 Redis 的字典结构包含两个哈希表: t…...

Redis的常用数据结构

三. Redis 的常用数据结构 (redis提供的查询功能, 不像mysql这么强大) 1. 认识数据类型和编码方式 常见数据结构 (数据类型) : string (字符串), list (列表), hash (哈希), set (集合), zset (有序集合). Redis 底层在实现上述数据结构的时候, 会在源码层面进行优化, 来达到…...

c++中的虚函数

在C中&#xff0c;虚函数&#xff08;Virtual Function&#xff09;是一种实现多态的重要机制&#xff0c;它允许在派生类中重写基类的函数&#xff0c;从而在运行时根据对象的实际类型调用相应的函数版本。 1. 虚函数的定义 虚函数是在基类中使用关键字virtual声明的函数。例…...

unreal engine5开发仿鬼泣5的游戏,把敌人击飞到空中4连击

UE5系列文章目录 文章目录 UE5系列文章目录前言一、实现思路二、具体蓝图 前言 unreal engine5开发仿鬼泣5的游戏&#xff0c;把敌人击飞到空中4连击&#xff0c;先看下效果 一、实现思路 unreal engine5开发仿鬼泣5的游戏&#xff0c;把敌人击飞到空中4连击 在Unreal Engi…...

蓝桥杯嵌入式第十四届模拟二(PWM、USART)

一.LED 先配置LED的八个引脚为GPIO_OutPut,锁存器PD2也是,然后都设置为起始高电平,生成代码时还要去解决引脚冲突问题 二.按键 按键配置,由原理图按键所对引脚要GPIO_Input 生成代码,在文件夹中添加code文件夹,code中添加fun.c、fun.h、headfile.h文件,去资源包中把lc…...

深挖 TypeScript 基础数据类型:应用与陷阱

在 TypeScript 的学习与实践过程中&#xff0c;对基础数据类型的深入理解和正确运用&#xff0c;是写出高质量代码的关键。本篇文章会通过探讨数据类型在实际场景中的应用&#xff0c;分析常见错误&#xff0c;帮助大家提升运用 TypeScript 基础数据类型的能力。​ 一、函数参…...