Lora微LLAMA模型实战

引言

本文介绍如何复现Alpaca-lora,即基于alpaca数据集用lora方法微调Llama模型。

环境准备

实验环境用的是lanyun,新用户点击注册可以送算力。

下载huggingface上的模型是一个令人头疼的问题,但在lanyun上可以通过在终端运行source /etc/network_turbo 配置加速下载 :

image-20250316145517497

如上图,速度还是很快的。

如果不是lanyun上可以尝试:export HF_ENDPOINT=https://hf-mirror.com ,但可能不太稳定。

Cuda版本、pytorch版本如下:

image-20250316145636288

安装依赖

将下面的内容复制到requirements.txt中:

accelerate
appdirs
loralib
bitsandbytes
black
black[jupyter]
datasets
fire
peft
transformers>=4.28.0
sentencepiece
gradio

比如我这里复制到 /root/lanyun-tmp/目录下。然后依次执行:

source /etc/network_turbo 
pip install -r requirements.txt

其输出可能为:

Collecting appdirs (from -r requirements.txt (line 2))
...
Successfully installed aiofiles-23.2.1 aiohappyeyeballs-2.6.1 aiohttp-3.11.13 aiosignal-1.3.2 annotated-types-0.7.0 appdirs-1.4.4 async-timeout-5.0.1 bitsandbytes-0.45.3 black-25.1.0 click-8.1.8 datasets-3.4.0 dill-0.3.8 fastapi-0.115.11 ffmpy-0.5.0 fire-0.7.0 frozenlist-1.5.0 gradio-5.21.0 gradio-client-1.7.2 groovy-0.1.2 loralib-0.1.2 markdown-it-py-3.0.0 mdurl-0.1.2 multidict-6.1.0 multiprocess-0.70.16 mypy-extensions-1.0.0 orjson-3.10.15 pandas-2.2.3 pathspec-0.12.1 peft-0.14.0 propcache-0.3.0 pyarrow-19.0.1 pydantic-2.10.6 pydantic-core-2.27.2 pydub-0.25.1 python-multipart-0.0.20 pytz-2025.1 requests-2.32.3 rich-13.9.4 ruff-0.11.0 safehttpx-0.1.6 semantic-version-2.10.0 sentencepiece-0.2.0 shellingham-1.5.4 starlette-0.46.1 termcolor-2.5.0 tokenize-rt-6.1.0 tomlkit-0.13.2 tqdm-4.67.1 typer-0.15.2 tzdata-2025.1 uvicorn-0.34.0 websockets-15.0.1 xxhash-3.5.0 yarl-1.18.3

等待依赖下载完毕。

模型格式转换

首先需要将LLaMA原始权重文件转换为Transformers库对应的模型文件格式,但我们也可以选择别人转换好的,比如 https://huggingface.co/dfurman/LLaMA-7B:

LLaMA-7B is a base model for text generation with 6.7B parameters and a 1T token training corpus. It was built and released by the FAIR team at Meta AI alongside the paper "LLaMA: Open and Efficient Foundation Language Models".This model repo was converted to work with the transformers package. It is under a bespoke non-commercial license, please see the LICENSE file for more details.

下面编写代码下载模型:

download_model.py:

import transformers
import torchmodel_name = "dfurman/llama-7b"tokenizer = transformers.AutoTokenizer.from_pretrained(model_name)
streamer = transformers.TextStreamer(tokenizer)model = transformers.LlamaForCausalLM.from_pretrained(model_name,torch_dtype=torch.bfloat16,device_map="auto"
)

等待执行完毕我们就下载好了想要的模型格式。

训练

单卡训练

克隆alpaca-lora项目的源码:

git clone https://github.com/tloen/alpaca-lora.git
cd alpaca-lora

修改alpaca-lora目录下的 finetune.py文件,将prepare_model_for_int8_training替换为prepare_model_for_kbit_training,不然新版(0.14.0)的peft会报错。

然后在该目录下执行:

python finetune.py \--base_model 'dfurman/llama-7b' \--data_path 'yahma/alpaca-cleaned' \--output_dir './lora-alpaca'

这里的dfurman/llama-7b是我们刚才下载好的模型;yahma/alpaca-cleaned,参考4项目任务原始的alpaca数据集质量不高,因此他们对该数据集进行了一个清理,得到了更高质量的alpaca-cleaned

Training Alpaca-LoRA model with params:
base_model: dfurman/llama-7b
data_path: yahma/alpaca-cleaned
output_dir: ./lora-alpaca
batch_size: 128
micro_batch_size: 4
num_epochs: 3
learning_rate: 0.0003
cutoff_len: 256
val_set_size: 2000
lora_r: 8
lora_alpha: 16
lora_dropout: 0.05
lora_target_modules: ['q_proj', 'v_proj']
train_on_inputs: True
add_eos_token: False
group_by_length: False
wandb_project: 
wandb_run_name: 
wandb_watch: 
wandb_log_model: 
resume_from_checkpoint: False
prompt template: alpaca
...                                                                                   | 5/1164 [01:49<6:57:53, 21.63s/it]

从上面可以看到一些默认的参数配置,但是需要训练7个小时左右,太慢了。finetune.py的代码是支持单机多卡的,因此我们重新创建一个4卡的实例。

多卡训练

下面来一步一步在Lanyun上操作一下:

image-20250316160428548

image-20250316160520634

这里我们选择了4卡,并且选择好了Cuda等版本。

等待创建完毕后:

image-20250316160646272

点击JupyterLab进入代码环境。

image-20250316160729009

进入后我们可以看到这样的解码,这里直接点击Terminal进入终端环境。

第一步执行:

source /etc/network_turbo 

第二步克隆项目:

git clone https://github.com/tloen/alpaca-lora.git
cd alpaca-lora

第三步安装依赖:

pip install -r requirements.txt

第四步修改alpaca-lora目录下的 finetune.py文件,将prepare_model_for_int8_training替换为prepare_model_for_kbit_training,主要修改有两处。

第五步利用数据并行,在4卡上进行训练:

nohup torchrun --nproc_per_node=4 --master_port=29005 finetune.py \--base_model 'dfurman/llama-7b' \--data_path 'yahma/alpaca-cleaned' \--num_epochs=10 \--cutoff_len=512 \--group_by_length \--output_dir='./lora-alpaca' \--lora_target_modules='[q_proj,k_proj,v_proj,o_proj]' \--lora_r=16 \--micro_batch_size=8 > output.log 2>&1 &

同时这里参考 https://huggingface.co/tloen/alpaca-lora-7b 上的例子调整下参数。

[2025-03-16 16:18:21,847] torch.distributed.run: [WARNING] 
[2025-03-16 16:18:21,847] torch.distributed.run: [WARNING] *****************************************
[2025-03-16 16:18:21,847] torch.distributed.run: [WARNING] Setting OMP_NUM_THREADS environment variable for each process to be 1 in default, to avoid your system being overloaded, please further tune the variable for optimal performance in your application as needed. 
[2025-03-16 16:18:21,847] torch.distributed.run: [WARNING] *****************************************
Training Alpaca-LoRA model with params:
base_model: dfurman/llama-7b
data_path: yahma/alpaca-cleaned
output_dir: ./lora-alpaca
batch_size: 128
micro_batch_size: 8
num_epochs: 10
learning_rate: 0.0003
cutoff_len: 512
val_set_size: 2000
lora_r: 16
lora_alpha: 16
lora_dropout: 0.05
lora_target_modules: ['q_proj', 'k_proj', 'v_proj', 'o_proj']
train_on_inputs: True
add_eos_token: False
group_by_length: True
wandb_project: 
wandb_run_name: 
wandb_watch: 
wandb_log_model: 
resume_from_checkpoint: False
prompt template: alpaca
...

这次会自动从huggingface上下载模型dfurman/llama-7b并开始单机多卡训练。

 trainable params: 16,777,216 || all params: 6,755,192,832 || trainable%: 0.24840%|▌                                                                                  4/3880 [00:30<6:16:57,  7.08s/it]

image-20250316164020138

显存使用如上,每个卡都用了16.8G。

4卡训练了5个小时左右,终于训练好了。

推理

在仓库根目录下执行:

python generate.py     --load_8bit     --base_model 'dfurman/llama-7b'     --lora_weights 'lora-alpaca'
AttributeError: module 'gradio' has no attribute 'inputs'

遇到了上面的错误,这是因为仓库的代码有点老,一种比较简单的方法是降低版本:

pip install gradio==3.43.1
Running on local URL:  http://0.0.0.0:7860To create a public link, set `share=True` in `launch()`.
IMPORTANT: You are using gradio version 3.43.1, however version 4.44.1 is available, please upgrade.
--------

顶着各种警告,终于跑起来了。

但是我们在Lanyun上无法访问这个端口,如果是个人电脑可以直接打开了。要在Lanyun上访问,需要通过端口映射开放端口:

image-20250317180326312

找到generate.py中195行这句代码,添加指定的server_port

    ).queue().launch(server_name="0.0.0.0", share=share_gradio, server_port=17860)

image-20250317181738506

启动成功后点击端口映射中的访问即可:

image-20250317181825796

finetune.py文件分析

该项目下的finetune.py脚本值得我们学习一下:

import os
import sys
from typing import Listimport fire
import torch
import transformers
from datasets import load_dataset"""
Unused imports:
import torch.nn as nn
import bitsandbytes as bnb
"""from peft import (LoraConfig,get_peft_model,get_peft_model_state_dict,prepare_model_for_int8_training,set_peft_model_state_dict,
)
from transformers import LlamaForCausalLM, LlamaTokenizer
# 自定义的提示词工具
from utils.prompter import Prompterdef train(# model/data paramsbase_model: str = "",  # the only required argumentdata_path: str = "yahma/alpaca-cleaned", # 会从huggingface上去下载output_dir: str = "./lora-alpaca", # 训练超参batch_size: int = 128, # 梯度累积后的批大小micro_batch_size: int = 4, # 实际的批大小num_epochs: int = 3, # 训练轮次learning_rate: float = 3e-4, cutoff_len: int = 256, # 最长长度val_set_size: int = 2000, # 验证集大小# lora 超参lora_r: int = 8, # 低秩矩阵的维度lora_alpha: int = 16, # 低秩矩阵的比例因子lora_dropout: float = 0.05, # LoRA层的dropout概率# 应用lora到 query 和 value的投影层(Linear层)lora_target_modules: List[str] = ["q_proj","v_proj",],# llm 超参train_on_inputs: bool = True,  # if False, masks out inputs in lossadd_eos_token: bool = False,group_by_length: bool = False,  # faster, but produces an odd training loss curve# wandb log 相关参数wandb_project: str = "",wandb_run_name: str = "",wandb_watch: str = "",  # options: false | gradients | allwandb_log_model: str = "",  # options: false | trueresume_from_checkpoint: str = None,  # either training checkpoint or final adapterprompt_template_name: str = "alpaca",  # The prompt template to use, will default to alpaca.
):if int(os.environ.get("LOCAL_RANK", 0)) == 0:print(f"Training Alpaca-LoRA model with params:\n"f"base_model: {base_model}\n"f"data_path: {data_path}\n"f"output_dir: {output_dir}\n"f"batch_size: {batch_size}\n"f"micro_batch_size: {micro_batch_size}\n"f"num_epochs: {num_epochs}\n"f"learning_rate: {learning_rate}\n"f"cutoff_len: {cutoff_len}\n"f"val_set_size: {val_set_size}\n"f"lora_r: {lora_r}\n"f"lora_alpha: {lora_alpha}\n"f"lora_dropout: {lora_dropout}\n"f"lora_target_modules: {lora_target_modules}\n"f"train_on_inputs: {train_on_inputs}\n"f"add_eos_token: {add_eos_token}\n"f"group_by_length: {group_by_length}\n"f"wandb_project: {wandb_project}\n"f"wandb_run_name: {wandb_run_name}\n"f"wandb_watch: {wandb_watch}\n"f"wandb_log_model: {wandb_log_model}\n"f"resume_from_checkpoint: {resume_from_checkpoint or False}\n"f"prompt template: {prompt_template_name}\n")assert (base_model), "Please specify a --base_model, e.g. --base_model='huggyllama/llama-7b'"#gradient_accumulation_steps = batch_size // micro_batch_size# 自定义了提示词工具类prompter = Prompter(prompt_template_name)device_map = "auto"# 分布式训练时指定的设备数量world_size = int(os.environ.get("WORLD_SIZE", 1))# 判断是否为分布式训练ddp = world_size != 1if ddp:device_map = {"": int(os.environ.get("LOCAL_RANK") or 0)}gradient_accumulation_steps = gradient_accumulation_steps // world_sizeuse_wandb = len(wandb_project) > 0 or ("WANDB_PROJECT" in os.environ and len(os.environ["WANDB_PROJECT"]) > 0)if len(wandb_project) > 0:os.environ["WANDB_PROJECT"] = wandb_projectif len(wandb_watch) > 0:os.environ["WANDB_WATCH"] = wandb_watchif len(wandb_log_model) > 0:os.environ["WANDB_LOG_MODEL"] = wandb_log_model# 使用transformers 加载Llama模型model = LlamaForCausalLM.from_pretrained(base_model,load_in_8bit=True,torch_dtype=torch.float16,device_map=device_map,)# 加载分词器tokenizer = LlamaTokenizer.from_pretrained(base_model)tokenizer.pad_token_id = (0  # unk. we want this to be different from the eos token)tokenizer.padding_side = "left"  # Allow batched inferencedef tokenize(prompt, add_eos_token=True):# there's probably a way to do this with the tokenizer settings# but again, gotta move fastresult = tokenizer(prompt,truncation=True,max_length=cutoff_len,padding=False,return_tensors=None,)if (result["input_ids"][-1] != tokenizer.eos_token_idand len(result["input_ids"]) < cutoff_lenand add_eos_token):result["input_ids"].append(tokenizer.eos_token_id)result["attention_mask"].append(1)result["labels"] = result["input_ids"].copy()return resultdef generate_and_tokenize_prompt(data_point):# 得到输入提示词full_prompt = prompter.generate_prompt(data_point["instruction"],data_point["input"],data_point["output"],)tokenized_full_prompt = tokenize(full_prompt)if not train_on_inputs:user_prompt = prompter.generate_prompt(data_point["instruction"], data_point["input"])tokenized_user_prompt = tokenize(user_prompt, add_eos_token=add_eos_token)user_prompt_len = len(tokenized_user_prompt["input_ids"])if add_eos_token:user_prompt_len -= 1tokenized_full_prompt["labels"] = [-100] * user_prompt_len + tokenized_full_prompt["labels"][user_prompt_len:]  # could be sped up, probablyreturn tokenized_full_prompt#  适配 INT8 训练,减少显存占用model = prepare_model_for_int8_training(model)# Lora配置config = LoraConfig(r=lora_r,lora_alpha=lora_alpha,target_modules=lora_target_modules,lora_dropout=lora_dropout,bias="none", task_type="CAUSAL_LM", # 任务类型为因果语言模型)# model = get_peft_model(model, config)if data_path.endswith(".json") or data_path.endswith(".jsonl"):data = load_dataset("json", data_files=data_path)else:data = load_dataset(data_path)# 从断点恢复if resume_from_checkpoint:# Check the available weights and load themcheckpoint_name = os.path.join(resume_from_checkpoint, "pytorch_model.bin")  # Full checkpointif not os.path.exists(checkpoint_name):checkpoint_name = os.path.join(resume_from_checkpoint, "adapter_model.bin")  # only LoRA model - LoRA config above has to fitresume_from_checkpoint = (False  # So the trainer won't try loading its state)# The two files above have a different name depending on how they were saved, but are actually the same.if os.path.exists(checkpoint_name):print(f"Restarting from {checkpoint_name}")adapters_weights = torch.load(checkpoint_name)set_peft_model_state_dict(model, adapters_weights)else:print(f"Checkpoint {checkpoint_name} not found")model.print_trainable_parameters()  # Be more transparent about the % of trainable params.if val_set_size > 0:train_val = data["train"].train_test_split(test_size=val_set_size, shuffle=True, seed=42)train_data = (train_val["train"].shuffle().map(generate_and_tokenize_prompt))val_data = (train_val["test"].shuffle().map(generate_and_tokenize_prompt))else:train_data = data["train"].shuffle().map(generate_and_tokenize_prompt)val_data = Noneif not ddp and torch.cuda.device_count() > 1:# keeps Trainer from trying its own DataParallelism when more than 1 gpu is availablemodel.is_parallelizable = Truemodel.model_parallel = Truetrainer = transformers.Trainer(model=model,train_dataset=train_data,eval_dataset=val_data,args=transformers.TrainingArguments(per_device_train_batch_size=micro_batch_size,gradient_accumulation_steps=gradient_accumulation_steps,warmup_steps=100,num_train_epochs=num_epochs,learning_rate=learning_rate,fp16=True,logging_steps=10,optim="adamw_torch",evaluation_strategy="steps" if val_set_size > 0 else "no",save_strategy="steps",eval_steps=200 if val_set_size > 0 else None,save_steps=200,output_dir=output_dir,save_total_limit=3,load_best_model_at_end=True if val_set_size > 0 else False,ddp_find_unused_parameters=False if ddp else None,group_by_length=group_by_length,report_to="wandb" if use_wandb else None,run_name=wandb_run_name if use_wandb else None,),data_collator=transformers.DataCollatorForSeq2Seq(tokenizer, pad_to_multiple_of=8, return_tensors="pt", padding=True), # pad_to_multiple_of = 8 对齐到 8 的倍数)model.config.use_cache = Falseold_state_dict = model.state_dictmodel.state_dict = (lambda self, *_, **__: get_peft_model_state_dict(self, old_state_dict())).__get__(model, type(model))if torch.__version__ >= "2" and sys.platform != "win32":# 加速模型推理和训练model = torch.compile(model)trainer.train(resume_from_checkpoint=resume_from_checkpoint)model.save_pretrained(output_dir)print("\n If there's a warning about missing keys above, please disregard :)")if __name__ == "__main__":fire.Fire(train)

参考

  1. https://huggingface.co/dfurman/LLaMA-7B
  2. https://github.com/tloen/alpaca-lora
  3. https://zhuanlan.zhihu.com/p/619426866
  4. https://github.com/gururise/AlpacaDataCleaned

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/diannao/73766.shtml
繁体地址,请注明出处:http://hk.pswp.cn/diannao/73766.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Maven常见问题汇总

Maven刷新,本地仓库无法更新 现象 This failure was cached in the local repository and resolution is not reattempted until the update interval of aliyunmaven has elapsed or updates are forced原因 因为上一次尝试下载&#xff0c;发现对应的仓库没有这个maven配置…

什么是站群服务器?站群服务器应该怎么选?

站群服务器是专门用于托管和管理多个网站的服务器。通常用于SEO优化、内容分发、广告推广等场景&#xff0c;用户可以通过一个服务器管理多个站点&#xff0c;提升效率并降低成本。选择站群服务器时&#xff0c;需根据业务需求、性能要求、IP资源等因素进行综合考虑。 什么是站…

分享一个项目中遇到的一个算法题

需求背景&#xff1a; 需求是用户要创建一个任务计划在未来执行&#xff0c;要求在创建任务计划的时候判断选择的时间是否符合要求&#xff0c;否则不允许创建&#xff0c;创建的任务类型有两种&#xff0c;一种是单次&#xff0c;任务只执行一次&#xff1b;另一种是周期&…

【LInux进程六】命令行参数和环境变量

【LInux进程六】命令行参数和环境变量 1.main函数的两个参数2.利用main函数实现一个简单的计算器3.环境变量之一&#xff1a;PATH4.修改PATH5.在命令行解释器bash中查看所有环境变量6.用自己写的程序查看环境变量7.main函数的第三个参数8.本地的环境变量和环境变量9.环境变量具…

时间轴版本-2.0

文章简述 这是本人自己封装的时间轴2.0版本的代码&#xff0c;用到了TypeScriptJavaScript 这篇文章只有代码和具体的使用方式&#xff0c;如果想看具体的讲解可以参考本人写的时间轴1.0版本的&#xff0c;在1.0版本中可能计算时间线的逻辑略有不同&#xff0c;但是大致的计算…

大语言模型的压缩技术

尽管人们对越来越大的语言模型一直很感兴趣&#xff0c;但MistralAI 向我们表明&#xff0c;规模只是相对而言的&#xff0c;而对边缘计算日益增长的兴趣促使我们使用小型语言获得不错的结果。压缩技术提供了一种替代方法。在本文中&#xff0c;我将解释这些技术&#xff0c;并…

大华HTTP协议在智联视频超融合平台中的接入方法

一. 大华HTTP协议介绍 大华HTTP协议是大华股份&#xff08;Dahua Technology&#xff09;为其安防监控设备开发的一套基于HTTP/HTTPS的通信协议&#xff0c;主要用于设备与客户端&#xff08;如PC、手机、服务器&#xff09;之间的数据交互。该协议支持设备管理、视频流获取、…

Linux内核实时机制28 - RT调度器11 - RT 组调度

Linux内核实时机制28 - RT调度器11 - RT 组调度 相关数据结构 内核中通过static int sched_rt_runtime_exceeded(struct rt_rq *rt_rq)函数来判断实时任务运行时间是否超出带宽限制,判断这个运行队列rt_rq的运行时间是否超过了额定的运行时间。而“运行时间”和“额定时间”都…

java,poi,提取ppt文件中的文字内容

注意&#xff0c;不涉及图片处理。 先上pom依赖&#xff1a; <!-- 处理PPTX文件 --><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>5.2.3</version></dependency><!--…

7、vue3做了什么

大佬认为有何优点&#xff1a; 组合式api----逻辑集中、对ts有更好的支持RFC–开放了一个讨论机制&#xff0c;可以看到每一个api的提案&#xff0c;方便源码维护&#xff0c;功能扩展&#xff0c;大家一起讨论 官方rfc响应式独立&#xff0c;new Proxy&#xff0c;天生自带来…

多人在线聊天系统,创建群,视频,语音,自带带授权码

多人在线聊天系统&#xff0c;创建群&#xff0c;视频&#xff0c;语音 带授权码&#xff0c;授权码限制 10 个网站&#xff0c;需要下载研究吧 在线聊天&#xff0c;创建群&#xff0c;表情&#xff0c;图片&#xff0c;文件&#xff0c;视频&#xff0c;语音&#xff0c;自…

数据结构概览

关键点&#xff1a; 数据结构是组织和存储数据的方式&#xff0c;帮助高效访问和操作数据。常见类型包括数组、链表、栈、队列、树和图&#xff0c;每种都有特定用途。代码示例和实际应用场景将帮助初学者理解这些概念。 什么是数据结构&#xff1f; 数据结构就像你整理书架或…

Android studio点击运行按钮在build\intermediates\apk\debug目录下生成的apk在真机上安装失败,提示test only

Android studio点击运行按钮在build\intermediates\apk\debug目录下生成的apk在真机上安装失败&#xff0c;提示test only DeepSeek R1 思考 15 秒 思考过程 针对Android Studio生成的APK在真机安装时提示“test only”的问题&#xff0c;以下是详细解决方案&#xff1a; 1.…

NFC 碰一碰发视频源码搭建,支持OEM

一、引言 NFC&#xff08;Near Field Communication&#xff09;近场通信技术&#xff0c;以其便捷、快速的数据交互特性&#xff0c;正广泛应用于各个领域。其中&#xff0c;NFC 碰一碰发视频这一应用场景&#xff0c;为用户带来了新颖且高效的视频分享体验。想象一下&#x…

Python基础语法全解析:从入门到实践

Python作为一门简洁高效、功能强大的编程语言&#xff0c;凭借其易读性和丰富的生态系统&#xff0c;已成为编程领域的“明星语言”。本文将系统讲解Python的核心语法&#xff0c;涵盖变量、数据类型、控制结构、函数、模块等核心概念&#xff0c;帮助读者快速掌握编程基础。 一…

TypeScript中的类型断言(type assertion),如何使用类型断言进行类型转换?

一、什么是类型断言&#xff1f; 类型断言&#xff08;Type Assertion&#xff09;是 TypeScript 中一种显式指定变量类型的方式&#xff0c;它告诉编译器&#xff1a;“我比编译器更清楚这个值的类型”。​这不是运行时类型转换&#xff0c;而是编译阶段的类型声明辅助机制。…

分区表和分表

分区表&#xff08;Partitioning&#xff09; 定义 分区表是将单个表的数据按照某种规则&#xff08;如范围、列表、哈希等&#xff09;划分为多个逻辑部分&#xff0c;每个部分称为一个分区。数据仍然存储在一个物理表中&#xff0c;但逻辑上被分割为多个分区。 特点 逻辑…

C++从入门到入土(八)——多态的原理

目录 前言 多态的原理 动态绑定与静态绑定 虚函数表 小结 前言 在前面的文章中&#xff0c;我们介绍了C三大特性之一的多态&#xff0c;我们主要介绍了多态的构成条件&#xff0c;但是对于多态的原理我们探讨的是不够深入的&#xff0c;下面这这一篇文章&#xff0c;我们将…

用Maven创建只有POM文件的项目

使用 mvn 创建一个仅包含 pom.xml 文件的父项目&#xff0c;可以借助 maven-archetype-quickstart 原型&#xff0c;然后移除不必要的文件&#xff0c;或者直接通过命令生成最简的 pom.xml 文件。以下是具体操作步骤&#xff1a; 一、方法一&#xff1a;使用原型创建后清理 1…

Linux目录理解

前言 最近在复习linux&#xff0c;发现有些目录总是忘记内容&#xff0c;发现有些还是得从原义和实际例子去理解会记忆深刻些。以下是个人的一些理解 Linux目录 常见的Linux下的目录如下&#xff1a; 1. 根目录 / (Root Directory) 英文含义&#xff1a;/ 是文件系统的根…