Datamodule 工具
float_or_int_or_none(value)
将给定值转换为浮点数、整数或 None。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
value
|
Union[str, float, int, None]
|
可以是字符串、浮点数、整数或 None 的值。 |
必需 |
返回
类型 | 描述 |
---|---|
Union[float, int, None]
|
Union[float, int, None]:基于输入值的浮点数、整数或 None。 |
如果输入值为 None 或 "None",则返回 None。如果输入值为整数或浮点数,则返回相同的值。如果输入值为字符串,则尝试将其转换为整数(如果可能),否则转换为浮点数。
源代码位于 bionemo/llm/utils/datamodule_utils.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
infer_global_batch_size(micro_batch_size, num_nodes, devices, accumulate_grad_batches=1, tensor_model_parallel_size=1, pipeline_model_parallel_size=1)
根据微批大小、节点数、设备数、梯度累积批次和模型并行大小推断全局批大小。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
micro_batch_size
|
int
|
微批大小。 |
必需 |
num_nodes
|
int
|
节点数。 |
必需 |
devices
|
int
|
设备数。 |
必需 |
accumulate_grad_batches
|
int
|
梯度累积批次。默认为 1。 |
1
|
tensor_model_parallel_size
|
int
|
张量模型并行大小。默认为 1。 |
1
|
pipeline_model_parallel_size
|
int
|
流水线模型并行大小。默认为 1。 |
1
|
返回
名称 | 类型 | 描述 |
---|---|---|
int |
int
|
全局批大小。 |
源代码位于 bionemo/llm/utils/datamodule_utils.py
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
infer_num_samples(limit_batches, num_samples_in_dataset, global_batch_size, stage)
根据 limit_batches 参数、数据集的长度和全局批大小推断样本数。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
limit_batches
|
Union[float, int, str, None]
|
批次数限制。可以是 0 到 1 之间的浮点数、整数、字符串或 None。如果为 None,则默认为 1.0。 |
必需 |
num_samples_in_dataset
|
int
|
数据集中的样本数。 |
必需 |
global_batch_size
|
int
|
全局批大小。 |
必需 |
stage
|
str
|
训练阶段。 |
必需 |
返回
名称 | 类型 | 描述 |
---|---|---|
int |
来自限制的样本数。 |
Raises
类型 | 描述 |
---|---|
ValueError
|
如果限制的样本数小于全局批大小,或者 limit_batches 参数无效。 |
如果 limit_batches 是 0 到 1 之间的浮点数,则样本数被推断为数据集样本数的一部分。如果 limit_batches 是大于或等于 1 的整数,则限制的样本数被推断为 limit_batches 和全局批大小的乘积。如果 limit_batches 为 None,则默认为 1.0,表示应使用所有数据集样本。
源代码位于 bionemo/llm/utils/datamodule_utils.py
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 |
|
parse_kwargs_to_arglist(kwargs)
将关键字参数字典转换为命令行参数列表。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
kwargs
|
Dict[str, Any]
|
一个字典,其中键是参数名称,值是参数值。 |
必需 |
返回
类型 | 描述 |
---|---|
List[str]
|
一个字符串列表,其中每个字符串都是 '--argument-name value' 格式的命令行参数。 |
源代码位于 bionemo/llm/utils/datamodule_utils.py
42 43 44 45 46 47 48 49 50 51 52 53 54 |
|