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

广东工程承包网站企业网址怎么做

广东工程承包网站,企业网址怎么做,网络推广公司排名,建网站的域名Introduction sat#xff08;SwissArmyTransformer#xff09;是一个灵活而强大的库#xff0c;用于开发您自己的Transformer变体。 sat是以“瑞士军刀”命名的#xff0c;这意味着所有型号#xff08;例如BERT、GPT、T5、GLM、CogView、ViT…#xff09;共享相同的backo…Introduction satSwissArmyTransformer是一个灵活而强大的库用于开发您自己的Transformer变体。 sat是以“瑞士军刀”命名的这意味着所有型号例如BERT、GPT、T5、GLM、CogView、ViT…共享相同的backone代码并通过一些超轻量级的mixin满足多种用途。 sat由deepspeed ZeRO和模型并行性提供支持旨在为大模型100M\~20B参数的预训练和微调提供最佳实践。 从 SwissArmyTransformer 0.2.x 迁移到 0.3.x 导入时将包名称从 SwissArmyTransformer 更改为 sat例如从 sat 导入 get_args。删除脚本中的所有--sandwich-ln使用layernorm-ordersandwich。更改顺序 from_pretrained(args, name) from_pretrained(name, args)。我们可以直接使用 from sat.model import AutoModel;model, args AutoModel.from_pretrained(roberta-base) 以 仅模型模式 加载模型而不是先初始化 sat。 安装 pip install SwissArmyTransformer 特征 添加与模型无关的组件例如前缀调整只需一行 前缀调整或 P 调整通过在每个注意力层中添加可训练参数来改进微调。使用我们的库可以轻松地将其应用于 GLM 分类或任何其他模型。 class ClassificationModel(GLMModel): # can also be BertModel, RobertaModel, etc. def __init__(self, args, transformerNone, **kwargs):super().__init__(args, transformertransformer, **kwargs)self.add_mixin(classification_head, MLPHeadMixin(args.hidden_size, 2048, 1))# Arm an arbitrary model with Prefix-tuning with this line!self.add_mixin(prefix-tuning, PrefixTuningMixin(args.num_layers, args.hidden_size // args.num_attention_heads, args.num_attention_heads, args.prefix_len)) GPT 和其他自回归模型在训练和推理过程中的行为有所不同。在推理过程中文本是逐个令牌生成的我们需要缓存以前的状态以提高效率。使用我们的库您只需要考虑训练期间的行为教师强制并通过添加 mixin 将其转换为缓存的自回归模型 model, args AutoModel.from_pretrained(glm-10b-chinese, args) model.add_mixin(auto-regressive, CachedAutoregressiveMixin()) # Generate a sequence with beam search from sat.generation.autoregressive_sampling import filling_sequence from sat.generation.sampling_strategies import BeamSearchStrategy output, *mems filling_sequence(model, input_seq,batch_sizeargs.batch_size,strategyBeamSearchStrategy(args.batch_size)) 使用最少的代码构建基于 Transformer 的模型。我们提到了 GLM它与标准转换器称为 BaseModel仅在位置嵌入和训练损失上有所不同。我们在编码的时候只需要关注相关的部分就可以了。 扩展整个定义 class BlockPositionEmbeddingMixin(BaseMixin):# Here define parameters for the mixindef __init__(self, max_sequence_length, hidden_size, init_method_std0.02):super(BlockPositionEmbeddingMixin, self).__init__()self.max_sequence_length max_sequence_lengthself.hidden_size hidden_sizeself.block_position_embeddings torch.nn.Embedding(max_sequence_length, hidden_size)torch.nn.init.normal_(self.block_position_embeddings.weight, mean0.0, stdinit_method_std)# Here define the method for the mixindef position_embedding_forward(self, position_ids, **kwargs):position_ids, block_position_ids position_ids[:, 0], position_ids[:, 1]position_embeddings self.transformer.position_embeddings(position_ids)block_position_embeddings self.block_position_embeddings(block_position_ids)return position_embeddings block_position_embeddingsclass GLMModel(BaseModel):def __init__(self, args, transformerNone, parallel_outputTrue):super().__init__(args, transformertransformer, parallel_outputparallel_output)self.add_mixin(block_position_embedding, BlockPositionEmbeddingMixin(args.max_sequence_length, args.hidden_size)) # Add the mixin for GLM 全方位的培训支持。 sat 旨在提供预训练和微调的最佳实践您只需要完成forward_step 和 create_dataset_function但可以使用超参数来更改有用的训练配置。 通过指定 --num_nodes、--num_gpus 和一个简单的主机文件将训练扩展到多个 GPU 或节点。 DeepSpeed 和模型并行性。 ZeRO-2 和激活检查点的更好集成。 自动扩展和改组训练数据和内存映射。 成功支持CogView2和CogVideo的训练。 目前唯一支持在 GPU 上微调 T5-10B 的开源代码库。 快速浏览 在 sat 中使用 Bert用于推理的最典型的 python 文件如下 # File: inference_bert.py from sat import get_args, get_tokenizer, AutoModel # Parse args, initialize the environment. This is necessary. args get_args() # Automatically download and load model. Will also dump model-related hyperparameters to args. model, args AutoModel.from_pretrained(bert-base-uncased, args) # Get the BertTokenizer according to args.tokenizer_type (automatically set). tokenizer get_tokenizer(args) # Here to use bert as you want! # ... 然后我们可以通过以下方式运行代码 SAT_HOME/path/to/download python inference_bert.py --mode inference 所有官方支持的模型名称都在 urls.py 中。 # File: finetune_bert.py from sat import get_args, get_tokenizer, AutoModel from sat.model.mixins import MLPHeadMixindef create_dataset_function(path, args):# Here to load the dataset# ...assert isinstance(dataset, torch.utils.data.Dataset)return datasetdef forward_step(data_iterator, model, args, timers):inputs next(data_iterator) # from the dataset of create_dataset_function.loss, *others model(inputs)return loss# Parse args, initialize the environment. This is necessary. args get_args() model, args AutoModel.from_pretrained(bert-base-uncased, args) tokenizer get_tokenizer(args) # Here to use bert as you want! model.del_mixin(bert-final) model.add_mixin(classification_head, MLPHeadMixin(args.hidden_size, 2048, 1)) # ONE LINE to train! # args already includes hyperparams such as lr, train-iters, zero-stage ... training_main(args, model_clsmodel, forward_step_functionforward_step, # user definecreate_dataset_functioncreate_dataset_function # user define ) 然后我们可以通过以下方式运行代码 deepspeed --include localhost:0,1 finetune_bert.py \--experiment-name ftbert \--mode finetune --train-iters 1000 --save /path/to/save \--train-data /path/to/train --valid-data /path/to/valid \--lr 0.00002 --batch-size 8 --zero-stage 1 --fp16 这里我们在 GPU 0,1 上使用数据并行。我们还可以通过 --hostfile/path/to/hostfile 在许多互连的机器上启动训练。请参阅教程了解更多详细信息。 要编写自己的模型您只需要考虑与标准 Transformer 的差异。例如如果你有一个改进注意力操作的想法 from sat.model import BaseMixin class MyAttention(BaseMixin):def __init__(self, hidden_size):super(MyAttention, self).__init__()# MyAttention may needs some new params, e.g. a learnable alpha.self.learnable_alpha torch.nn.Parameter(torch.ones(hidden_size))# This is a hook function, the name attention_fn is special.def attention_fn(q, k, v, mask, dropoutNone, **kwargs):# Code for my attention.# ...return attention_results 这里的attention_fn是一个钩子函数用新函数替换默认动作。所有可用的钩子都在transformer_defaults.py中。现在我们可以使用 add_mixin 将更改应用到所有转换器例如 BERT、Vit 和 CogView。请参阅教程了解更多详细信息。 教程 How to use pretrained models collected in sat?Why and how to train models in sat? Citation Currently we dont have a paper, so you dont need to formally cite us!~ If this project helps your research or engineering, use \footnote{https://github.com/THUDM/SwissArmyTransformer} to mention us and recommend SwissArmyTransformer to others. The tutorial for contributing sat is on the way! The project is based on (a user of) DeepSpeed, Megatron-LM and Huggingface transformers. Thanks for their awesome work. 训练指导 The Training API 我们提供了一个简单但功能强大的训练APItraining_main()它不仅限于我们的Transformer模型还适用于任何torch.nn.Module。 from sat import get_args, training_main from sat.model import AutoModel, BaseModel args get_args() # to pretrain from scratch, give a class obj model BaseModel # to finetuned from a given model, give a torch.nn.Module model AutoModel.from_pretrained(bert-base-uncased, args)training_main(args, model_clsmodel,forward_step_functionforward_step,create_dataset_functiondataset_func,handle_metrics_functionNone,init_functionNone ) 以上是使用 sat 的标准训练计划的不完整示例。 Training_main 接受 5 个参数必需model_cls继承 torch.nn.Module 的类型对象或我们训练的 torch.nn.Module 对象。 必需forward_step_function一个自定义函数输入 data_iterator、model、args、timers、returns loss、{#39;metric0#39;: m0, ...}。 必填create_dataset_function返回一个torch.utils.data.Dataset用于加载。我们的库会自动将数据分配给多个worker并将数据迭代器交给forward_step_function。 可选handle_metrics_function在评估过程中处理特殊指标。 可选init_function在训练之前更改模型的钩子对于继续训练很有用。 有关完整示例请参阅 Finetune BERT 示例。
http://www.hkea.cn/news/14465414/

相关文章:

  • dz如何做门户网站浏览器打不开二级网页
  • 沧州网站建设沧州免费域名申请入口
  • 网站描述怎么写比较好wordpress双语插件
  • 事业单位报名网站长春建设信息网站
  • 沙坪坝网站建设公司选哪家好安徽省住房城乡建设部网站
  • 水利建设工程网站官网网站搭建
  • 成都网站建设怎么样淘客网站seo怎么做
  • 济南网站优化公司哪家好软件公司找项目
  • 数据处理网站开发中装建设
  • 义乌网站建设优化推广广州seo公司哪个比较好
  • python做网站用什么软件合肥软件开发网站建设
  • 清远做网站的广告公司接单软件
  • 10000ip网站怎么做北京seo软件
  • 外贸自建站源码网页设计实验报告格式模板
  • 关于网站建设分类北京seo优化公司
  • 网站后台如何修改参数企业做网站用dedeCMS免费吗
  • 网站 关键词库重庆公司注销的流程及需提供的材料
  • 网络广告网站怎么做网站免费模板资源
  • 建材企业网站推广方案北京设计制作公司
  • 嵊州市住房和城乡建设局网站网络游戏代理平台
  • 郑州网站建设讯息湘潭网站建设出色磐石网络
  • 山东川畅信息技术有限公司网站建设2024年楼市大局已定
  • 怎么做网站快捷方式有没有在网上做ps赚钱的网站
  • 网站更换模板重庆公众号开发服务
  • 盐城北京网站建设网站层级关系
  • 如何让网站被百度收录详情页设计图片
  • 做网站是用什么软件运营培训班学费大概多少
  • 网站绝对路径301如何发布网站教程
  • 为什么选择做游戏网站南通营销网站制作
  • 改了网站关键词用自己的名字设计logo