第五节:GLM-4v-9b模型model加载源码解读(模型相关参数方法解读)
文章目录
- 前言
- 一、GLM-4v-9b模型model加载源码解读
- 1、GLM-4v-9b模型model加载主函数源码
- 2、GLM-4v-9b模型model加载源码源码解读
- 3、GLM-4v-9b自定义模型类源码解读
- 二、基于GLM-4v-9b模型获取模型输入参数等内容源码解读(from_pretrained-->huggingface)
- 1、from_pretrained函数参数解读(huggingface)
- 2、config文件路径获取(huggingface)
- 3、adapter_config文件路径获取与加载(huggingface)
- 4、config文件方法获取
- 1、config源码
- 2、from_pretrained函数kwargs参数传递
- 3、config内容获取
- config加工源码调用
- AutoConfig.from_pretrained函数源码内容
- AutoConfig.from_pretrained的PretrainedConfig.get_config_dict函数源码解读
- config的类class加载源码解读
- 4、小节总结
前言
清华智普的GLM-4v-9b模型,作为优化的多模态大模型,特别适用于国内应用场景,解决了国外模型本地化不足的问题。本专栏提供环境安装、数据处理、视觉与语言模型源码理解,并基于Hugging Face重构GLM模型搭建教程,帮助理解、修改和应用GLM墨西哥,指导搭建多模态大模型,帮助读者自由搭建与修改大模型。本节给出GLM-4-9B模型加载相关参数获取方法源码解读内容。
第一节:GLM-4v-9B大模型安装、推理与训练详细教程
第二节:GLM-4v-9B数据加载源码解读
第三节:GLM-4v-9B数据加载之huggingface数据加载方法教程(通用大模型数据加载实列)
第四节:GLM-4v-9b模型的tokenizer源码解读
第五节:GLM-4v-9b模型model加载源码解读(模型相关参数方法解读)
第六节:GLM-4v-9b模型加载源码解读(模型加载方法解读)
第七节:GLM-4v-9b模型的视觉模型源码解读
第八节:GLM-4v-9b模型的大语言模型源码解读(ChatGLMForConditionalGeneration)
第九节:通过Debug解析ChatGLMForConditionalGeneration的数据流,理解GLM-4v-9b模型架构
第十节:通过Debug解析ChatGLMModel的数据流,理解视觉与语言模型结合架构
第十一节:利用huggingface重构GLM-4v-9B模型数据处理代码Demo
第十二节:利用huggingface重构GLM-4v-9B训练模型代码Demo
第十一、十二节是在理解GLM-4v-9B模型后,使用huggignface重新构建/搭建GLM-4v-9B模型,使读者能自由构建多模态大模型!
本节给出GLM-4v-9b模型model加载,而加载使用huggingface方法,是十分简单,然而huggingface源码确为麻烦。为此,本节以glm的model加载示例重点解读huggingface加载model源码。该小节主要解释,模型加载前准备工作,特别需要知道使用下面代码可以完成自定义模型加载:
"auto_map": {"AutoConfig": "configuration_chatglm.ChatGLMConfig","AutoModel": "modeling_chatglm.ChatGLMForConditionalGeneration","AutoModelForCausalLM": "modeling_chatglm.ChatGLMForConditionalGeneration","AutoModelForSeq2SeqLM": "modeling_chatglm.ChatGLMForConditionalGeneration","AutoModelForSequenceClassification": "modeling_chatglm.ChatGLMForSequenceClassification"},
一、GLM-4v-9b模型model加载源码解读
我们解读下model加载流程吧,实际这个部分与huggingface相关,我们先给出与huggingface加载相关源码
1、GLM-4v-9b模型model加载主函数源码
来源:finetune_demo/finetune_vision.py-->load_tokenizer_and_model函数
我给出GLM-4v-9b模型加载函数,其主要是调用huggingface内容,我给出主函数加载源码如下:
def load_tokenizer_and_model(model_dir: str,peft_config: Optional[PeftConfig] = None,
):tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)if peft_config is not None:model = AutoModelForCausalLM.from_pretrained(model_dir,trust_remote_code=True,empty_init=False,use_cache=False,torch_dtype=torch.bfloat16, # Must use BFloat 16# cache_dir = '/extend_disk/disk3/tj/GLM-4V-9B/GLM-4-main/THUDM/cache_dir')model = get_peft_model(model, peft_config)model.print_trainable_parameters()else:model = AutoModelForCausalLM.from_pretrained(model_dir,trust_remote_code=True,empty_init=False,use_cache=False,torch_dtype=torch.bfloat16)return tokenizer, model
2、GLM-4v-9b模型model加载源码源码解读
来源:finetune_demo/finetune_vision.py-->load_tokenizer_and_model函数
实际模型使用huggingface的AutoModelForCausalLM.from_pretrained
来构建,而get_peft_model
是高效微调使用函数,也就是模型加载也是比较简单,其主要还是huggingface内容源码解读,我将后面重点解读,而GLM-4v-9b源码如下:
if peft_config is not None:model = AutoModelForCausalLM.from_pretrained(model_dir,trust_remote_code=True,empty_init=False,use_cache=False,torch_dtype=torch.bfloat16 # Must use BFloat 16)model = get_peft_model(model, peft_config)model.print_trainable_parameters()
else:model = AutoModelForCausalLM.from_pretrained(model_dir,trust_remote_code=True,empty_init=False,use_cache=False,torch_dtype=torch.bfloat16)
3、GLM-4v-9b自定义模型类源码解读
在权重文件中有个config.json
文件,这也是huggingface最重要配置文件。该文件有个参数auto_map"字典,里面包含了很多方法,和之前tokenizer加载自定义方法有点类似。auto_map有AutoModel等内容,用来加载模型,列如"AutoModel": "modeling_chatglm.ChatGLMForConditionalGeneration"就是在modeling_chatglm.py文件中加载 ChatGLMForConditionalGeneration类。我给出json这个文件内容如下。
"auto_map": {"AutoConfig": "configuration_chatglm.ChatGLMConfig","AutoModel": "modeling_chatglm.ChatGLMForConditionalGeneration","AutoModelForCausalLM": "modeling_chatglm.ChatGLMForConditionalGeneration","AutoModelForSeq2SeqLM": "modeling_chatglm.ChatGLMForConditionalGeneration","AutoModelForSequenceClassification": "modeling_chatglm.ChatGLMForSequenceClassification"},
我也给出GLM-4v-9b自定义ChatGLMForConditionalGeneration类部分内容,如下:
class ChatGLMForConditionalGeneration(ChatGLMPreTrainedModel):def __init__(self, config: ChatGLMConfig, empty_init=True, device=None):super().__init__(config)self.max_sequence_length = config.max_lengthself.transformer = ChatGLMModel(config, empty_init=empty_init, device=device)self.config = configdef _update_model_kwargs_for_generation(self,outputs: ModelOutput,model_kwargs: Dict[str, Any],is_encoder_decoder: bool = False,) -> Dict[str, Any]:# update past_key_valuescache_name, cache = self._extract_past_from_model_output(outputs)model_kwargs[cache_name] = cache# update attention maskif "attention_mask" in model_kwargs:attention_mask = model_kwargs["attention_mask"]model_kwargs["attention_mask"] = torch.cat([attention_mask, attention_mask.new_ones((attention_mask.shape[0], 1))], dim=-1)# update position idsif "position_ids" in model_kwargs:position_ids = model_kwargs["position_ids"]new_position_id = position_ids[..., -1:].clone()new_position_id += 1model_kwargs["position_ids"] = torch.cat([position_ids, new_position_id], dim=-1)model_kwargs["is_first_forward"] = Falsereturn model_kwargs
二、基于GLM-4v-9b模型获取模型输入参数等内容源码解读(from_pretrained–>huggingface)
来源:transforms/models/auto/auto_factory.py-->class _BaseAutoModelClass-->from_pretrained函数
1、from_pretrained函数参数解读(huggingface)
这里我需要说明from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)参数,特别是kwargs可以直接提供对应参数,如config文件,而from_pretrained内部如下图:
2、config文件路径获取(huggingface)
通过以下代码就可以获取config文件路径,给了resolved_config_file变量
if commit_hash is None:if not isinstance(config, PretrainedConfig):# We make a call to the config file first (which may be absent) to get the commit hash as soon as possibleresolved_config_file = cached_file(pretrained_model_name_or_path,CONFIG_NAME,_raise_exceptions_for_gated_repo=False,_raise_exceptions_for_missing_entries=False,_raise_exceptions_for_connection_errors=False,**hub_kwargs,)commit_hash = extract_commit_hash(resolved_config_file, commit_hash)else:commit_hash = getattr(config, "_commit_hash", None)
如图显示如下:
3、adapter_config文件路径获取与加载(huggingface)
这个代码是类似lora方法获得内容加载,首先是加载adapter_config.josn文件,该文件也是在pretrained_model_name_or_path
路径中存在,使用find_adapter_config_file函数
来获取adapter_config.json路径,其源码如下:
if is_peft_available():if adapter_kwargs is None:adapter_kwargs = {}if token is not None:adapter_kwargs["token"] = tokenmaybe_adapter_path = find_adapter_config_file(pretrained_model_name_or_path, _commit_hash=commit_hash, **adapter_kwargs)if maybe_adapter_path is not None:with open(maybe_adapter_path, "r", encoding="utf-8") as f:adapter_config = json.load(f)adapter_kwargs["_adapter_model_path"] = pretrained_model_name_or_pathpretrained_model_name_or_path = adapter_config["base_model_name_or_path"]
如果存在adapter_config.json路径就执行with open(maybe_adapter_path, "r", encoding="utf-8") as f
获得其参数。
4、config文件方法获取
1、config源码
我们给出整体源码代码,如下:
if not isinstance(config, PretrainedConfig):kwargs_orig = copy.deepcopy(kwargs)# ensure not to pollute the config object with torch_dtype="auto" - since it's# meaningless in the context of the config object - torch.dtype values are acceptableif kwargs.get("torch_dtype", None) == "auto":_ = kwargs.pop("torch_dtype")# to not overwrite the quantization_config if config has a quantization_configif kwargs.get("quantization_config", None) is not None:_ = kwargs.pop("quantization_config")config, kwargs = AutoConfig.from_pretrained(pretrained_model_name_or_path,return_unused_kwargs=True,trust_remote_code=trust_remote_code,code_revision=code_revision,_commit_hash=commit_hash,**hub_kwargs,**kwargs,)# if torch_dtype=auto was passed here, ensure to pass it onif kwargs_orig.get("torch_dtype", None) == "auto":kwargs["torch_dtype"] = "auto"if kwargs_orig.get("quantization_config", None) is not None:kwargs["quantization_config"] = kwargs_orig["quantization_config"]
kwargs存在quantization_config与torch_dtype会直接剔除,共下面函数调用。
2、from_pretrained函数kwargs参数传递
仅接着,from_pretrained函数的参数kwargs将传递,如下代码:
kwargs_orig = copy.deepcopy(kwargs)
3、config内容获取
config加工源码调用
获得config函数,使用以下源码,如下:
config, kwargs = AutoConfig.from_pretrained(pretrained_model_name_or_path, # 模型路径return_unused_kwargs=True,trust_remote_code=trust_remote_code,code_revision=code_revision,_commit_hash=commit_hash,**hub_kwargs,**kwargs,)
AutoConfig.from_pretrained函数源码内容
来源:transforms/models/auto/configuration_auto.py-->class AutoConfig-->from_pretrained函数
我们继续解读AutoConfig.from_pretrained函数所有源码,如下:
@classmethod
@replace_list_option_in_docstrings()
def from_pretrained(cls, pretrained_model_name_or_path, **kwargs):r"""..."""use_auth_token = kwargs.pop("use_auth_token", None)if use_auth_token is not None:warnings.warn("The `use_auth_token` argument is deprecated and will be removed in v5 of Transformers. Please use `token` instead.",FutureWarning,)if kwargs.get("token", None) is not None:raise ValueError("`token` and `use_auth_token` are both specified. Please set only the argument `token`.")kwargs["token"] = use_auth_tokenkwargs["_from_auto"] = Truekwargs["name_or_path"] = pretrained_model_name_or_pathtrust_remote_code = kwargs.pop("trust_remote_code", None)code_revision = kwargs.pop("code_revision", None)config_dict, unused_kwargs = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)has_remote_code = "auto_map" in config_dict and "AutoConfig" in config_dict["auto_map"]has_local_code = "model_type" in config_dict and config_dict["model_type"] in CONFIG_MAPPINGtrust_remote_code = resolve_trust_remote_code(trust_remote_code, pretrained_model_name_or_path, has_local_code, has_remote_code)if has_remote_code and trust_remote_code:class_ref = config_dict["auto_map"]["AutoConfig"]config_class = get_class_from_dynamic_module(class_ref, pretrained_model_name_or_path, code_revision=code_revision, **kwargs)if os.path.isdir(pretrained_model_name_or_path):config_class.register_for_auto_class()return config_class.from_pretrained(pretrained_model_name_or_path, **kwargs)elif "model_type" in config_dict:try:config_class = CONFIG_MAPPING[config_dict["model_type"]]except KeyError:raise ValueError(f"The checkpoint you are trying to load has model type `{config_dict['model_type']}` ""but Transformers does not recognize this architecture. This could be because of an ""issue with the checkpoint, or because your version of Transformers is out of date.")return config_class.from_dict(config_dict, **unused_kwargs)else:# Fallback: use pattern matching on the string.# We go from longer names to shorter names to catch roberta before bert (for instance)for pattern in sorted(CONFIG_MAPPING.keys(), key=len, reverse=True):if pattern in str(pretrained_model_name_or_path):return CONFIG_MAPPING[pattern].from_dict(config_dict, **unused_kwargs)raise ValueError(f"Unrecognized model in {pretrained_model_name_or_path}. "f"Should have a `model_type` key in its {CONFIG_NAME}, or contain one of the following strings "f"in its name: {', '.join(CONFIG_MAPPING.keys())}")
AutoConfig.from_pretrained的PretrainedConfig.get_config_dict函数源码解读
简单说就是读取路径config文件内容,重要代码如下:
config_dict, unused_kwargs = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
传递路径pretrained_model_name_or_path变量中,通过PretrainedConfig.get_config_dict
函数可以直接获得config.json文件内容与其它unused_kwargs 内容,而unused_kwargs就是kwargs内容。如下图所示:
而unused_kwargs来源kwargs,但有些参数被剔除了pop,如下图所示:
config的类class加载源码解读
这里就很关键了,我们需要加载config对应class方法了,当然你可以自己继承huggingface构建一个自己想处理的config方法class,也可以调用已有的。我们来看下源代码如下:
if has_remote_code and trust_remote_code:class_ref = config_dict["auto_map"]["AutoConfig"]config_class = get_class_from_dynamic_module(class_ref, pretrained_model_name_or_path, code_revision=code_revision, **kwargs)if os.path.isdir(pretrained_model_name_or_path):config_class.register_for_auto_class()return config_class.from_pretrained(pretrained_model_name_or_path, **kwargs)
elif "model_type" in config_dict:try:config_class = CONFIG_MAPPING[config_dict["model_type"]]except KeyError:raise ValueError(f"The checkpoint you are trying to load has model type `{config_dict['model_type']}` ""but Transformers does not recognize this architecture. This could be because of an ""issue with the checkpoint, or because your version of Transformers is out of date.")return config_class.from_dict(config_dict, **unused_kwargs)
else:# Fallback: use pattern matching on the string.# We go from longer names to shorter names to catch roberta before bert (for instance)for pattern in sorted(CONFIG_MAPPING.keys(), key=len, reverse=True):if pattern in str(pretrained_model_name_or_path):return CONFIG_MAPPING[pattern].from_dict(config_dict, **unused_kwargs)
①、如果config存在auto_map字典的AutoConfig内容
config.json的auto_map如下所示内容:
"auto_map": {"AutoConfig": "configuration_chatglm.ChatGLMConfig","AutoModel": "modeling_chatglm.ChatGLMForConditionalGeneration","AutoModelForCausalLM": "modeling_chatglm.ChatGLMForConditionalGeneration","AutoModelForSeq2SeqLM": "modeling_chatglm.ChatGLMForConditionalGeneration","AutoModelForSequenceClassification": "modeling_chatglm.ChatGLMForSequenceClassification"},
此时使用下面加载config
if has_remote_code and trust_remote_code:class_ref = config_dict["auto_map"]["AutoConfig"] #configuration_chatglm.ChatGLMConfigconfig_class = get_class_from_dynamic_module(class_ref, pretrained_model_name_or_path, code_revision=code_revision, **kwargs)
然后会进入get_class_from_dynamic_module方法来加载class,我下面说给函数主要源码来解读,首先module_file, class_name = class_reference.split(".")
将class_ref的configuration_chatglm.ChatGLMConfig字符分成文件和类名, module_file=configuration_chatglm, class_name=ChatGLMConfig。然后在通过以下代码来调用:
# And lastly we get the class inside our newly created module
final_module = get_cached_module_file(repo_id, # 文件路径module_file + ".py", # configuration_chatglm.pycache_dir=cache_dir,force_download=force_download,resume_download=resume_download,proxies=proxies,token=token,revision=code_revision,local_files_only=local_files_only,repo_type=repo_type,
)
将final_module变成路径transformers_modules/glm-4v-9b/configuration_chatglm.py
最后在经过get_class_in_module
方法来获得config的类class,其代码如下:
return get_class_in_module(class_name, final_module, force_reload=force_download)
将其结果返回到config_class
中,这样就得到了config的方法了。
就是config, kwargs = AutoConfig.from_pretrained(*)
的返回config内容了,该内容实际是继承PretrainedConfig类,该方法就是configuration_chatglm.py
的文件了,该文件如下:
from transformers import PretrainedConfigclass ChatGLMConfig(PretrainedConfig):model_type = "chatglm"def __init__(self,num_layers=28,padded_vocab_size=65024,hidden_size=4096,ffn_hidden_size=13696,kv_channels=128,num_attention_heads=32,seq_length=2048,hidden_dropout=0.0,classifier_dropout=None,attention_dropout=0.0,layernorm_epsilon=1e-5,rmsnorm=True,apply_residual_connection_post_layernorm=False,post_layer_norm=True,add_bias_linear=False,add_qkv_bias=False,bias_dropout_fusion=True,multi_query_attention=False,multi_query_group_num=1,rope_ratio=1,apply_query_key_layer_scaling=True,attention_softmax_in_fp32=True,fp32_residual_connection=False,pre_seq_len=None,prefix_projection=False,boi_token_id=None,eoi_token_id=None,**kwargs):self.num_layers = num_layersself.vocab_size = padded_vocab_sizeself.padded_vocab_size = padded_vocab_sizeself.hidden_size = hidden_sizeself.ffn_hidden_size = ffn_hidden_sizeself.kv_channels = kv_channelsself.num_attention_heads = num_attention_headsself.seq_length = seq_lengthself.hidden_dropout = hidden_dropoutself.classifier_dropout = classifier_dropoutself.attention_dropout = attention_dropoutself.layernorm_epsilon = layernorm_epsilonself.rmsnorm = rmsnormself.apply_residual_connection_post_layernorm = apply_residual_connection_post_layernormself.post_layer_norm = post_layer_normself.add_bias_linear = add_bias_linearself.add_qkv_bias = add_qkv_biasself.bias_dropout_fusion = bias_dropout_fusionself.multi_query_attention = multi_query_attentionself.multi_query_group_num = multi_query_group_numself.rope_ratio = rope_ratioself.apply_query_key_layer_scaling = apply_query_key_layer_scalingself.attention_softmax_in_fp32 = attention_softmax_in_fp32self.fp32_residual_connection = fp32_residual_connectionself.pre_seq_len = pre_seq_lenself.prefix_projection = prefix_projectionself.boi_token_id = boi_token_idself.eoi_token_id = eoi_token_idsuper().__init__(**kwargs)
4、小节总结
config.json文件内容设置auto_map来实现huggingface调用我们自己构建的ChatGLMConfig类,而"AutoConfig": “configuration_chatglm.ChatGLMConfig”,的configuration_chatglm为文件py名称,ChatGLMConfig为类别名称。同时,进一步说明auto_map内容 "auto_map": { "AutoConfig": "configuration_chatglm.ChatGLMConfig", "AutoModel": "modeling_chatglm.ChatGLMForConditionalGeneration", "AutoModelForCausalLM": "modeling_chatglm.ChatGLMForConditionalGeneration", "AutoModelForSeq2SeqLM": "modeling_chatglm.ChatGLMForConditionalGeneration", "AutoModelForSequenceClassification": "modeling_chatglm.ChatGLMForSequenceClassification" },
其它方法都可以通过这个方法来调用对应的方法。
相关文章:
第五节:GLM-4v-9b模型model加载源码解读(模型相关参数方法解读)
文章目录 前言一、GLM-4v-9b模型model加载源码解读1、GLM-4v-9b模型model加载主函数源码2、GLM-4v-9b模型model加载源码源码解读3、GLM-4v-9b自定义模型类源码解读 二、基于GLM-4v-9b模型获取模型输入参数等内容源码解读(from_pretrained-->huggingface)1、from_pretrained函…...
Unity3D仿星露谷物语开发7之事件创建动画
1、目标 掌握事件通知的Publisher - Subscriber设计模式,并通过事件通知触发动画。 2、发布者/订阅者模式 首先,定义事件Event 然后,Publisher触发事件 最后,Subscriber订阅事件并进行处理 (1)创建动作…...
学校知网中的加锁论文下载不了怎么办
最近有同学求助在学校下载知网论文,有加锁标识的论文下载不了。这是因为各高校订购的都不是数据库全库,加锁的论文是超出订购范围的资源所以下载不了。下面就来讲下解决办法: 首先选一个涵盖数据库多,各个数据库资源权限高的文献…...
算法 双指针技巧
文章目录 双指针[leetcode167 两数之和](https://leetcode.cn/problems/two-sum-ii-input-array-is-sorted/description/)分析题解 [leetcode88 合并两个有序数组](https://leetcode.cn/problems/merge-sorted-array/description/)分析题解 [leetcode142 环形链表](https://lee…...
Spring Boot注解总结大全【案例详解,一眼秒懂】
SpringBootApplication 功能:这是Spring Boot应用的核心注解,它是一个组合注解,实际上相当于同时使用了Configuration、EnableAutoConfiguration和ComponentScan。它标记在主应用类上,用于开启Spring Boot的自动配置功能ÿ…...
手动修改nginx-rtmp模块,让nginx-rtmp-module支持LLHLS
文章目录 1. 背景2. 开发环境搭建2.1 ffmpeg在ubuntu上安装2.2 nginx-rtmp-module在ubuntu上安装2.3 安装vscode环境2. 修改nginx-rtmp-module2.1 主要更新内容2.2 新增配置项2.3 代码更新3. LLHLS验证方法3.1 配置验证3.2 功能验证4. 注意事项5. 已知问题6. 后续计划1. 背景 …...
在Visual Studio 2022中配置C++计算机视觉库Opencv
本文主要介绍下载OpenCV库以及在Visual Studio 2022中配置、编译C计算机视觉库OpenCv的方法 1.Opencv库安装 首先,我们需要安装OpenCV库,作为一个开源库,我们可以直接在其官网下载Releases - OpenCV,如果官网下载过慢&#x…...
Unity全局雾效
1、全局雾效是什么 全局雾效(Global Fog)是一种视觉效果,用于在3D场景中模拟大气中的雾气对远处物体的遮挡 它通过在场景中加入雾的效果,使得距离摄像机较远的物体看起来逐渐被雾气覆盖,从而创造出一种朦胧、模糊的视…...
2024 高频 Java 面试合集整理 (1000 道附答案解析)
2024 年马上就快要过去了,总结了上半年各类 Java 面试题,初中级和中高级都有,包括 Java 基础,JVM 知识面试题库,开源框架面试题库,操作系统面试题库,多线程面试题库,Tcp 面试题库&am…...
Java CPU飙升 排查
一、概述 CPU 是整个电脑的核心计算资源,CPU的最小执行单元是 线程; 在现代操作系统中,进程和线程是两种主要的调度单位; 进程是程序中正在运行的一个应用程序,而线程是系统分配处理器时间资源的基本单位。一个进程至少…...
vue中的css深度选择器v-deep 配合!important
当 <style> 标签有 scoped 属性时,它的 CSS 只作用于当前组件中的元素,父组件的样式将不会渗透到子组件。 如果你希望 scoped 样式中的一个选择器能够作用得“更深”,例如影响子组件,你可以使用深度选择器。 ::v-deep { } 举…...
设计模式--工厂方法模式【创建型模式】
设计模式的分类 我们都知道有 23 种设计模式,这 23 种设计模式可分为如下三类: 创建型模式(5 种):单例模式、工厂方法模式、抽象工厂模式、建造者模式、原型模式。结构型模式(7 种)࿱…...
K8S Ingress 服务配置步骤说明
部署Pod服务 分别使用kubectl run和kubectl apply 部署nginx和tomcat服务 # 快速启动一个nginx服务 kubectl run my-nginx --imagenginx --port80# 使用yaml创建tomcat服务 kubectl apply -f my-tomcat.yamlmy-tomcat.yaml apiVersion: apps/v1 kind: Deployment metadata:n…...
32. 线程、进程与协程
一、什么是多任务 如果一个操作系统上同时运行了多个程序,那么称这个操作系统就是 多任务的操作系统,例如:Windows、Mac、Android、IOS、Harmony 等。如果是一个程序,它可以同时执行多个事情,那么就称为 多任务的程序。…...
华为实训课笔记 2024 1223-1224
华为实训 12/2312/24 12/23 [Huawei]stp enable --开启STP display stp brief --查询STP MSTID Port Role STP State Protection 实例ID 端口 端口角色 端口状态 是否开启保护[Huawei]display stp vlan xxxx --查询制定vlan的生成树计算结…...
麒麟信安参编的《能源企业数字化转型能力评价 技术可控》团体标准发布
近日,中国能源研究会发布公告,《能源企业数字化转型能力评价 技术可控》团体标准发布。该标准由麒麟信安与国网湖北省电力有限公司武汉供电公司、国网智能电网研究院有限公司、中能国研(北京)电力科学研究院等单位联合编制。 《能…...
绿色环保木塑复合材料自动化生产线设计书
《绿色环保木塑复合材料自动化生产线设计书》 一、项目概述 随着全球对环境保护和可持续发展的日益重视,绿色环保材料的研发与生产成为了热门领域。木塑复合材料作为一种新型的绿色环保材料,它将木材纤维与塑料通过特定工艺复合而成,兼具木材与塑料的双重特性,具有防水、…...
渗透测试-前端加密分析之RSA加密登录(密钥来源服务器)
本文是高级前端加解密与验签实战的第6篇文章,本系列文章实验靶场为Yakit里自带的Vulinbox靶场,本文讲述的是绕过RSA加密来爆破登录。 分析 这里的代码跟上文的类似,但是加密的公钥是通过请求服务端获取的 http://127.0.0.1:8787/crypto/js/…...
数据应用与数据平台如何测试?与普通测试有什么不同?
首先我们一起了解一下数据应用测试的对象是什么。第一个是数据报表这一块,数据报表包含了我们常见的业务分析报表、经常能看到的一些数据大屏之类。 第二块是数据平台,数据应用平台主要有一些智能营销平台,比如说画像分析平台,自助…...
基于Qlearning强化学习的机器人路线规划matlab仿真
目录 1.算法仿真效果 2.算法涉及理论知识概要 3.MATLAB核心程序 4.完整算法代码文件获得 1.算法仿真效果 matlab2022a仿真结果如下(完整代码运行后无水印): 训练过程 测试结果 仿真操作步骤可参考程序配套的操作视频。 2.算法涉及理论…...
零基础微信小程序开发——小程序的宿主环境(保姆级教程+超详细)
🎥 作者简介: CSDN\阿里云\腾讯云\华为云开发社区优质创作者,专注分享大数据、Python、数据库、人工智能等领域的优质内容 🌸个人主页: 长风清留杨的博客 🍃形式准则: 无论成就大小,…...
用Moninfo.exe轻松获取显示器EDID
我们天天在用显示器,但显示器的一些关键参数却总是记不住。有时为了配置电脑,有时为了发挥显示器的极限性能,有时为了定制驱动,等等,都需要获取显示器的EDID数据。有些工具虽然可以读出EDID,但难以解读那一…...
【开源库 | xlsxio】C/C++读写.xlsx文件,xlsxio 在 Linux(Ubuntu18.04)的编译、交叉编译
😁博客主页😁:🚀https://blog.csdn.net/wkd_007🚀 🤑博客内容🤑:🍭嵌入式开发、Linux、C语言、C、数据结构、音视频🍭 ⏰发布时间⏰: 2024-12-20 …...
全国青少年信息学奥林匹克竞赛(信奥赛)备考实战之分支结构(switch语句)
if语句处理多个分支时需要用if-else if结构,分支越多,嵌套的if语句层就越多,程序不但庞大、复杂,理解起来也比较困难。在C编程中,针对有些问题除了使用if-else if结构之外,还有switch语句也可以实现&#x…...
SQL Server数据库多主模式解决方案
SQL Server 本身并不直接支持多主模式(Multi-Master Replication),即多个数据库实例可以同时进行写操作,并且这些更改会自动同步到其他实例。不过,SQL Server 提供了多种高可用性和复制解决方案,可以实现类似多主模式的功能。以下是几种常见的方法: 1. Always On 可用性…...
如何训练Stable Diffusion 模型
训练Stable Diffusion模型是一个复杂且资源密集的过程,通常需要大量的计算资源(如GPU或TPU)和时间。Stable Diffusion是一种基于扩散模型的生成式AI,能够根据文本提示生成高质量的图像。它的训练过程涉及多个步骤,包括…...
网络编程(王铭东老师)笔记
网络编程的目的 1.将多个设备通过网络进行连接在一起,可以将数据共享。 基础知识-01-ip地址 1.引入 为了能够确定网络数据收发双方是哪台电脑,需要用ip来标记电脑。 2.什么是地址 地址就是用来标记地点的 3.ip地址的作用 作用:在逻辑上标…...
项目亮点案例
其实对我来说是日常操作,但是如果在面试的时候面试者能把日常的事情总结好发出来,其实足矣。 想让别人认同项目,选取的示例需要包含以下要素: 亮点项目四要素:明确的目标,问题点,解决方法和结果…...
ShardingSphere-Proxy 连接实战:从 Golang 原生 SQL 到 GORM 的应用
在这篇文章《ShardingSphereProxy:快速入门》中,我们介绍了如何通过 Navicat 连接 ShardingSphere-Proxy。 实际上,ShardingSphere-Proxy 兼容标准的 SQL 和原生数据库协议,因此你可以使用任何 MySQL 客户端与其进行连接,包括 Go…...
uniapp验证码
一、 页面结构 假设你有一个发送短信按钮,点击按钮时会触发发送短信并启动倒计时。 <template><view><button click"sendSms" :disabled"isSending">{{ buttonText }}</button></view> </template>二、脚…...
C/C++基础知识复习(43)
1) 什么是运算符重载?如何在 C 中进行运算符重载? 运算符重载是指在 C 中为现有的运算符定义新的行为,使得它们能够用于用户定义的数据类型(如类或结构体)。通过运算符重载,可以让自定义类型像内置数据类型…...
GIT安装过程
文章目录 下载安装包安装过程验证安装Git的基本使用 Git的安装可以通过以下步骤完成 下载安装包 首先,访问Git官网(https://git-scm.com/)或Git for Windows(https://gitforwindows.org/)下载对应系统的安装包。 对于Windows系统,通常…...
评估大语言模型在药物基因组学问答任务中的表现:PGxQA
这篇文献主要介绍了一个名为PGxQA的资源,用于评估大语言模型(LLM)在药物基因组学问答任务中的表现。 研究背景 药物基因组学(Pharmacogenomics, PGx)是精准医学中最有前景的领域之一,通过基因指导的治疗…...
[HNCTF 2022 Week1]你想学密码吗?
下载附件用记事本打开 把这些代码放在pytho中 # encode utf-8 # python3 # pycryptodemo 3.12.0import Crypto.PublicKey as pk from hashlib import md5 from functools import reducea sum([len(str(i)) for i in pk.__dict__]) funcs list(pk.__dict__.keys()) b reduc…...
MongoDB教程001:基本常用命令(数据库操作和集合操作)
1.1 案例需求 存放文章评论的数据存放到MongoDB中,数据结构参考如下: 数据库:【articledb】 专栏文章评论comment字段名称字段含义字段类型备注_id(MongoDB自动生成)IDObjectId或StringMongo的主键的字段articleId文…...
Springboot logback 日志打印配置文件,每个日志文件100M,之后滚动到下一个日志文件,日志保留30天(包含traceid)
全部配置 logback.xml <?xml version"1.0" encoding"UTF-8"?> <configuration debug"false"><property name"LOG_HOME" value"log"/><property name"LOG_NAME" value"admin"/&g…...
flink sink kafka
接上文:一文说清flink从编码到部署上线 之前写了kafka source,现在补充kafka sink。完善kafka相关操作。 环境说明:MySQL:5.7;flink:1.14.0;hadoop:3.0.0;操作系统&#…...
vue万达地产物业缴费分析系统
摘 要 随着互联网趋势的到来,各行各业都在考虑利用互联网将自己推广出去,最好方式就是建立自己的互联网系统,并对其进行维护和管理。在现实运用中,应用软件的工作规则和开发步骤,采用Java技术建设万达地产物业缴费分析…...
数据库 MYSQL的概念
数据库的概念 数据库是按照数据结 构来组织、存储和管理数据的系统,它允许用户高效地存储、检索、更新和管理数据 database:用来组织,存储,管理数据的仓库 数据库的管理系统:DBMS,实现对数据的有效储值&am…...
docker 容器的基本使用
docker 容器 一、docker是什么? 软件的打包技术,就是将算乱的多个文件打包为一个整体,打包技术在没有docker容器之前,一直是有这种需求的,比如上节课我把我安装的虚拟机给你们打包了,前面的这种打包方式是…...
Nginx IP优化限制策略
Nginx 如何限制每个 IP 地址的连接数,优化资源分配? Nginx 限制每个 IP 地址的连接数 Nginx 提供了多种机制来限制单个 IP 地址所能建立的同时连接数,这对于防止资源耗尽和提高服务稳定性至关重要。以下是几种有效策略: 1. 使用…...
某科技局国产服务器PVE虚拟化技术文档
环境介绍 硬件配置 服务器品牌:黄河 型号:Huanghe 2280 V2 Cpu型号:kunpeng-920 磁盘信息 :480SSD * 2 ,4T*4 网卡:板载四口千兆 如下表 四台服务器同等型号配置,均做单节点虚拟化,数据保护采用底层r…...
新能源汽车锂离子电池各参数的时间序列关系
Hi,大家好,我是半亩花海。为了进一步开展新能源汽车锂离子电池的相关研究,本文主要汇总并介绍了电动汽车的锂离子电池的各项参数,通过 MATLAB 软件对 Oxford Dataset 的相关数据集进行数据处理与分析,进一步研究各项参…...
单片机:实现自动关机电路(附带源码)
单片机实现自动关机电路 在许多嵌入式系统或便携式设备中,自动关机功能非常重要,尤其是在电池供电的设备中,防止设备长时间开启以节省电能。自动关机电路的基本功能是检测设备是否处于待机状态,若一定时间内未收到用户操作信号或…...
/etc/fstab 文件学习systemd与该文件关系
文章目录 一、文件字段1.1、设备标识1.2、挂载点1.3、文件系统类型1.4、挂载选项1.5、dump1.5、fsck顺序 二、/etc/fstab 与systemd 的关系2.1、/etc/fstab 与systemd 的关系2.2、systemd 之前/etc/fstab生效过程2.3、systemd 时代/etc/fstab生效过程 三、相关知识3.1、如何更具…...
springcloud基础
一 SpringCloud简介 1.1 SpringCloud是什么 SpringCloud,基于SpringBoot提供了一套微服务解决方案,包括服务注册与发现,配置中心,全链路监控,服务网关,负载均衡,熔断器等组件,除了基于NetFli…...
全面解析 Kubernetes 流量负载均衡:iptables 与 IPVS 模式
目录 Kubernetes 中 Service 的流量负载均衡模式 1. iptables 模式 工作原理 数据路径 优点 缺点 适用场景 2. IPVS 模式 工作原理 数据路径 优点 缺点 适用场景 两种模式的对比 如何切换模式 启用 IPVS 模式 验证模式 总结 Kubernetes 中 Service 的流量负载…...
HTML+CSS+JS制作汽车网站(内附源码,含5个页面)
一、作品介绍 HTMLCSSJS制作一个汽车网站,包含首页、新车发布页、预约试驾页、最新资讯页、品牌故事页等5个静态页面。其中每个页面都包含一个导航栏、一个主要区域和一个底部区域。 二、页面结构 1. 顶部导航栏 包含logo、主导航菜单(首页、新车、二…...
GraalVM完全指南:云原生时代下使用GraalVM将Spring Boot 3应用转换为高效Windows EXE文件
一、前言 在现代软件开发中,启动速度和资源利用率常常是衡量应用性能的关键指标。对于基于Spring Boot的应用来说,虽然它们易于开发和部署,但JVM的启动时间有时会成为一个瓶颈。本文介绍如何使用GraalVM将Spring Boot 3应用编译成原生Windows可执行文件(EXE),从而显著提…...
微软开源GraphRAG的使用教程-使用自定义数据测试GraphRAG
微软在今年4月份的时候提出了GraphRAG的概念,然后在上周开源了GraphRAG,Github链接见https://github.com/microsoft/graphrag,截止当前,已有6900Star。 安装教程 官方推荐使用Python3.10-3.12版本,我使用Python3.10版本安装时,在…...