Generates the host-side Ops to enqueue the shards of a tuple. sharded_inputs is a list, one for each shard, of lists of Tensors. sharded_inputs[0] is the tuple of Tensors to use to feed shard 0 if the queue. Returns the host-side Ops that must be run to enqueue the sharded tuple. Th
(self,
sharded_inputs,
tpu_ordinal_function=None,
placement_function=None)
| 550 | device_ordinal=tpu_ordinal) |
| 551 | |
| 552 | def generate_enqueue_ops(self, |
| 553 | sharded_inputs, |
| 554 | tpu_ordinal_function=None, |
| 555 | placement_function=None): |
| 556 | """Generates the host-side Ops to enqueue the shards of a tuple. |
| 557 | |
| 558 | sharded_inputs is a list, one for each shard, of lists of |
| 559 | Tensors. sharded_inputs[0] is the tuple of Tensors to use to feed |
| 560 | shard 0 if the queue. Returns the host-side Ops that must be run to |
| 561 | enqueue the sharded tuple. The Op for shard i is colocated with the inputs |
| 562 | for shard i. |
| 563 | |
| 564 | Implicitly freezes the queue configuration if it is not already |
| 565 | frozen. If the configuration has already been frozen, and is not |
| 566 | compatible with the types and shapes of sharded_inputs, an error |
| 567 | will be raised. |
| 568 | |
| 569 | Args: |
| 570 | sharded_inputs: a list of lists of Tensors. The length of the outer list |
| 571 | determines the number of shards. Each inner list indicates the types |
| 572 | and shapes of the tuples in the corresponding shard. |
| 573 | tpu_ordinal_function: if not None, a function that takes the |
| 574 | shard index as input and returns the ordinal of the TPU device |
| 575 | the shard's infeed should be placed on. tpu_ordinal_function must be |
| 576 | set if the inputs are placed on CPU devices. |
| 577 | placement_function: if not None, a function that takes the shard index as |
| 578 | input and returns the host device where the enqueue op should be placed |
| 579 | on. |
| 580 | |
| 581 | Returns: |
| 582 | A list of host-side Ops, one for each shard, that when executed together |
| 583 | will enqueue a full-size element of infeed. |
| 584 | |
| 585 | Raises: |
| 586 | ValueError: if the queue configuration has previously been frozen and the |
| 587 | shapes of the elements of sharded_inputs are not compatible with the |
| 588 | frozen configuration; or if the shapes of the elements of sharded_inputs |
| 589 | don't form a consistent unsharded tuple; or if the elements of a tuple |
| 590 | have different device constraints. |
| 591 | TypeError: if the queue configuration has previously been frozen and the |
| 592 | types of the elements of sharded_inputs are not compatible with the |
| 593 | frozen configuration; or if the types of the elements of sharded_inputs |
| 594 | don't form a consistent unsharded tuple. |
| 595 | """ |
| 596 | self.set_configuration_from_sharded_input_tensors(sharded_inputs) |
| 597 | self.freeze() |
| 598 | if self._generated_enqueue_ops: |
| 599 | raise ValueError("Can't generate two enqueue Ops from the same queue") |
| 600 | self._generated_enqueue_ops = True |
| 601 | if tpu_ordinal_function is None: |
| 602 | tpu_ordinal_function = lambda index: -1 |
| 603 | name_prefix = "%s/enqueue" % self._name |
| 604 | return [ |
| 605 | self._generate_enqueue_op( |
| 606 | shard, |
| 607 | name_prefix, |
| 608 | index, |
| 609 | tpu_ordinal=tpu_ordinal_function(index), |
nothing calls this directly
no test coverage detected