(self, is_training)
| 94 | |
| 95 | @parameterized.parameters(False, True) |
| 96 | def test_zipinput(self, is_training): |
| 97 | cfg = ZipInput.default_config().set( |
| 98 | name="input", |
| 99 | is_training=is_training, |
| 100 | inputs={ |
| 101 | "0": self._input_config( |
| 102 | [1, 2, 3, 4, 5, 6, 7, 8, 9], batch_size=3, out_signature="number_1", repeat=None |
| 103 | ), |
| 104 | "1": self._input_config( |
| 105 | [11, 12, 13, 14, 15, 16, 17, 18, 19], |
| 106 | batch_size=2, |
| 107 | out_signature="number_2", |
| 108 | repeat=None, |
| 109 | ), |
| 110 | }, |
| 111 | ) |
| 112 | dataset = cfg.instantiate(parent=None) |
| 113 | expected_train_batches = [ |
| 114 | { |
| 115 | "0": {"number_1": jnp.asarray([1, 2, 3]), "index": jnp.asarray([0, 1, 2])}, |
| 116 | "1": {"number_2": jnp.asarray([11, 12]), "index": jnp.asarray([0, 1])}, |
| 117 | }, |
| 118 | { |
| 119 | "0": {"number_1": jnp.asarray([4, 5, 6]), "index": jnp.asarray([3, 4, 5])}, |
| 120 | "1": {"number_2": jnp.asarray([13, 14]), "index": jnp.asarray([2, 3])}, |
| 121 | }, |
| 122 | ] |
| 123 | expected_eval_batches = [ |
| 124 | { |
| 125 | "0": {"number_1": jnp.asarray([1, 2, 3]), "index": jnp.asarray([0, 1, 2])}, |
| 126 | "1": {"number_2": jnp.asarray([11, 12]), "index": jnp.asarray([0, 1])}, |
| 127 | }, |
| 128 | { |
| 129 | "0": {"number_1": jnp.asarray([4, 5, 6]), "index": jnp.asarray([3, 4, 5])}, |
| 130 | "1": {"number_2": jnp.asarray([13, 14]), "index": jnp.asarray([2, 3])}, |
| 131 | }, |
| 132 | ] |
| 133 | expected_batches = expected_train_batches if is_training else expected_eval_batches |
| 134 | for batch_index, batch in enumerate(dataset): |
| 135 | if batch_index >= len(expected_batches): |
| 136 | break |
| 137 | self.assertNestedAllClose(as_tensor(expected_batches[batch_index]), batch) |
| 138 | self.assertEqual( |
| 139 | batch_index, |
| 140 | len(expected_batches), # pylint: disable=undefined-loop-variable |
| 141 | ) |
| 142 | |
| 143 | dataset = cfg.instantiate(parent=None) |
| 144 | for batch_index, batch in enumerate(dataset.dataset()): |
| 145 | if batch_index >= len(expected_batches): |
| 146 | break |
| 147 | self.assertNestedAllClose(as_tensor(expected_batches[batch_index]), batch) |
| 148 | self.assertEqual( |
| 149 | batch_index, |
| 150 | len(expected_batches), # pylint: disable=undefined-loop-variable |
| 151 | ) |
| 152 | |
| 153 |
nothing calls this directly
no test coverage detected