Generates the device-side Op to dequeue a tuple from the queue. Implicitly freezes the queue configuration if it is not already frozen, which will raise errors if the shapes and types have not been fully specified. Args: tpu_device: The TPU device ordinal where the infeed ins
(self, tpu_device=0)
| 458 | self._validate() |
| 459 | |
| 460 | def generate_dequeue_op(self, tpu_device=0): |
| 461 | """Generates the device-side Op to dequeue a tuple from the queue. |
| 462 | |
| 463 | Implicitly freezes the queue configuration if it is not already |
| 464 | frozen, which will raise errors if the shapes and types have not |
| 465 | been fully specified. |
| 466 | |
| 467 | Args: |
| 468 | tpu_device: The TPU device ordinal where the infeed instruction should be |
| 469 | placed. If None, no explicit placement will be performed, and it is up |
| 470 | to the user to call this API from within a proper TPU device scope. |
| 471 | The XLA code will fail if the TPU dequeue instruction is not bound to |
| 472 | any device. |
| 473 | |
| 474 | Returns: |
| 475 | A list of Outputs corresponding to a shard of infeed dequeued |
| 476 | into XLA, suitable for use within a replicated block. |
| 477 | |
| 478 | Raises: |
| 479 | ValueError: if the types or shapes of the tuple elements have not been |
| 480 | set; or if a dequeue op has already been generated. |
| 481 | """ |
| 482 | self.freeze() |
| 483 | if self._generated_dequeue_op: |
| 484 | raise ValueError("Can't generate two dequeue Ops from the same queue") |
| 485 | self._generated_dequeue_op = True |
| 486 | full_name = "%s/dequeue" % self._name |
| 487 | sharded_shapes = [ |
| 488 | policy.get_sharded_shape(shape) |
| 489 | for (shape, policy) in zip(self._tuple_shapes, self._sharding_policies) |
| 490 | ] |
| 491 | if tpu_device is not None: |
| 492 | with ops.device(tpu.core(tpu_device)): |
| 493 | return tpu_ops.infeed_dequeue_tuple( |
| 494 | dtypes=self._tuple_types, shapes=sharded_shapes, name=full_name) |
| 495 | else: |
| 496 | return tpu_ops.infeed_dequeue_tuple( |
| 497 | dtypes=self._tuple_types, shapes=sharded_shapes, name=full_name) |
| 498 | |
| 499 | def _generate_enqueue_op(self, |
| 500 | inputs, |
no test coverage detected