Megatron数据集兼容性
DatasetDistributedNondeterministic
基类: AssertionError
数据集不是本地确定性的。
源代码位于 `bionemo/testing/megatron_dataset_compatibility.py`
48 49 |
|
DatasetLocallyNondeterministic
基类: AssertionError
数据集不是本地确定性的。
源代码位于 `bionemo/testing/megatron_dataset_compatibility.py`
44 45 |
|
assert_dataset_compatible_with_megatron(dataset, index=0, assert_elements_equal=assert_dict_tensors_approx_equal)
确保数据集通过 Megatron 确定性约束的一些基本健全性检查。
测试的约束
- dataset[i] 无论设备如何都返回相同的元素
- dataset[i] 不调用已知的有问题的随机化过程 (当前为 `torch.manual_seed`)。
随着发现更多约束,应将其添加到此测试中。
源代码位于 `bionemo/testing/megatron_dataset_compatibility.py`
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 |
|
assert_dataset_elements_not_equal(dataset, index_a=0, index_b=1, assert_elements_equal=assert_dict_tensors_approx_equal)
测试在采用随机性的数据集上,例如掩码,两个索引返回不同元素的情况。
注意:如果您的数据集没有任何类型的随机性,只需使用 `assert_dataset_compatible_with_megatron` 测试并跳过此测试。此测试适用于您想测试数据集是否将随机变换应用于元素作为索引函数的情况,实际上对于映射到同一底层对象的两个不同索引执行此操作。此测试还在后台运行 `assert_dataset_compatible_with_megatron`,因此如果您执行此操作,则无需再执行另一个。
对于 epoch 上采样方法,某些底层索引(例如 index=0)将被某些包装数据集对象多次调用。例如,如果您的数据集长度为 1,并且您将其包装在一个上采样器中,该上采样器通过将索引 0 映射到 0,将 1 映射到 0 来将其映射到长度 2,然后在该包装器中,我们将随机性应用于结果,并且我们期望每次调用都使用不同的掩码,即使底层对象是相同的。同样,此测试仅适用于采用随机性的数据集。我们的一些数据集采用的另一种方法是使用一个特殊索引,该索引捕获底层索引和 epoch 索引。索引的这个元组在内部用于为掩码播种。如果使用这种类型的数据集,则 index_a 可以是 (epoch=0, idx=0),而 index_b 可以是 (epoch=1, idx=0),例如。我们希望这些返回不同的随机特征。
有效使用此测试的想法是识别您有两个索引返回相同的底层对象,但您期望数据集对每个索引应用不同随机化的情况。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
dataset
|
Dataset[TensorCollectionOrTensor]
|
具有随机性(例如掩码)的数据集对象以进行测试。 |
必需 |
index_a
|
Index
|
某个元素的索引。默认为 0。 |
0
|
index_b
|
Index
|
不同元素的索引。默认为 1。 |
1
|
assert_elements_equal
|
Callable[[TensorCollectionOrTensor, TensorCollectionOrTensor], None]
|
用于比较两个返回的批次元素的功能。默认为 `assert_dict_tensors_approx_equal`,它适用于张量和张量字典。 |
assert_dict_tensors_approx_equal
|
源代码位于 `bionemo/testing/megatron_dataset_compatibility.py`
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 117 118 119 120 121 122 123 124 125 126 127 |
|
assert_dict_tensors_approx_equal(actual, expected)
断言两个张量相等。
源代码位于 `bionemo/testing/megatron_dataset_compatibility.py`
33 34 35 36 37 38 39 40 41 |
|