微调回归器
ESM2FineTuneSeqConfig
dataclass
基类:ESM2GenericConfig[ESM2FineTuneSeqModel, RegressorLossReduction]
, IOMixinWithGettersSetters
ExampleConfig 是一个用于配置模型的数据类。
ModelParallelConfig 中的 Timers 是 megatron 向前兼容所必需的。
源代码位于 bionemo/esm2/model/finetune/finetune_regressor.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
get_loss_reduction_class()
返回 RegressorLossReduction 类。
源代码位于 bionemo/esm2/model/finetune/finetune_regressor.py
178 179 180 |
|
ESM2FineTuneSeqModel
基类:ESM2Model
适用于在下游任务上微调的 ESM2 模型。
源代码位于 bionemo/esm2/model/finetune/finetune_regressor.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
__init__(config, *args, post_process=True, include_embeddings=False, **kwargs)
构建适用于微调的 ESM2 模型实例。
源代码位于 bionemo/esm2/model/finetune/finetune_regressor.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
forward(*args, **kwargs)
推理。
源代码位于 bionemo/esm2/model/finetune/finetune_regressor.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
InMemorySingleValueDataset
基类:Dataset
一个内存数据集,将字符串分词为 BertSample 实例。
源代码位于 bionemo/esm2/model/finetune/finetune_regressor.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
|
__getitem__(index)
获取给定索引处的 BertSample。
源代码位于 bionemo/esm2/model/finetune/finetune_regressor.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
__init__(data, tokenizer=tokenizer.get_tokenizer(), seed=np.random.SeedSequence().entropy)
初始化单值回归微调的数据集。
这是一个内存数据集,不对序列应用掩码。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
data
|
Sequence[Tuple[str, float]]
|
包含序列和目标数据的元组序列。 |
必需 |
tokenizer
|
BioNeMoESMTokenizer
|
要使用的分词器。默认为 tokenizer.get_tokenizer()。 |
get_tokenizer()
|
seed
|
int
|
用于重现性的随机种子。此种子与要检索的样本的索引混合,以确保 getitem 是确定性的,但在不同的运行中可以是随机的。如果为 None,则生成一个随机种子。 |
entropy
|
源代码位于 bionemo/esm2/model/finetune/finetune_regressor.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
|
__len__()
数据集的大小。
源代码位于 bionemo/esm2/model/finetune/finetune_regressor.py
208 209 210 |
|
MegatronMLPHead
基类:MegatronModule
用于序列级回归的 MLP 类。
源代码位于 bionemo/esm2/model/finetune/finetune_regressor.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
__init__(config)
构造函数。
源代码位于 bionemo/esm2/model/finetune/finetune_regressor.py
97 98 99 100 101 102 103 104 105 106 |
|
forward(hidden_states)
推理。
源代码位于 bionemo/esm2/model/finetune/finetune_regressor.py
108 109 110 111 112 113 114 115 |
|
RegressorLossReduction
基类:BERTMLMLossWithReduction
用于计算回归输出的 MSE 损失的类。
此类用于计算损失,以及记录跨微批次的缩减损失。
源代码位于 bionemo/esm2/model/finetune/finetune_regressor.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
forward(batch, forward_out)
计算微批次内的损失。微批次是单个 GPU 上的数据批次。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
batch
|
Dict[str, Tensor]
|
传递到 LitAutoEncoder 内部原始 forward 的数据批次。 |
必需 |
forward_out
|
Dict[str, Tensor]
|
分类头内部 forward 方法的输出。 |
必需 |
返回
类型 | 描述 |
---|---|
Tuple[Tensor, PerTokenLossDict | SameSizeLossDict]
|
包含以下内容的元组:[ |
源代码位于 bionemo/esm2/model/finetune/finetune_regressor.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
reduce(losses_reduced_per_micro_batch)
跨微批次工作。(单个 gpu 上的数据)。
注意:这目前仅适用于日志记录,此损失不会用于反向传播。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
losses_reduced_per_micro_batch
|
Sequence[SameSizeLossDict]
|
forward 输出的列表 |
必需 |
返回
类型 | 描述 |
---|---|
Tensor
|
损失均值的张量。(用于日志记录)。 |
源代码位于 bionemo/esm2/model/finetune/finetune_regressor.py
79 80 81 82 83 84 85 86 87 88 89 90 91 |
|