class_docstr: Wraps a custom device which attempts to propagate tensor layouts.
class_docstr_tok: ["Wraps","a","custom","device","which","attempts","to","propagate","tensor","layouts","."]
docstr: Packs tensors into a DTensor handle on this DTensor device.
  
  Packing and unpacking are inverse operations:
  
  ```
  * unpack(pack(tensors)) == tensors
  * pack(unpack(dtensor)) == dtensor
  ```
  
  Refer to `dtensor.pack` for more information.
  
  Args:
    tensors: The list of tensors to pack into a DTensor.
    layout: The layout of the DTensor to be created.
  
  Returns:
    A DTensor created from the individual component tensors.
  
  Raises:
    RuntimeError: When not called eagerly.
docstr_tok: ["Packs","tensors","into","a","DTensor","handle","on","this","DTensor","device",".","Packing","and","unpacking","are","inverse","operations",":","``","`","*","unpack","(","pack","(","tensors",")",")","==","tensors","*","pack","(","unpack","(","dtensor",")",")","==","dtensor","``","`","Refer","to","`","dtensor.pack","`","for","more","information",".","Args",":","tensors",":","The","list","of","tensors","to","pack","into","a","DTensor",".","layout",":","The","layout","of","the","DTensor","to","be","created",".","Returns",":","A","DTensor","created","from","the","individual","component","tensors",".","Raises",":","RuntimeError",":","When","not","called","eagerly","."]
code: def pack(
      self, tensors: Sequence[Any], layout: layout_lib.Layout
  ) -> Any:
      """Packs tensors into a DTensor handle on this DTensor device.
  
      Packing and unpacking are inverse operations:
  
      ```
      * unpack(pack(tensors)) == tensors
      * pack(unpack(dtensor)) == dtensor
      ```
  
      Refer to `dtensor.pack` for more information.
  
      Args:
        tensors: The list of tensors to pack into a DTensor.
        layout: The layout of the DTensor to be created.
  
      Returns:
        A DTensor created from the individual component tensors.
  
      Raises:
        RuntimeError: When not called eagerly.
      """
      if not context.executing_eagerly():
          raise RuntimeError("`pack` must be called eagerly.")
      self._register_mesh(layout.mesh)
      with ops.device(self.name):
          if all(
              isinstance(t, sparse_tensor.SparseTensor) for t in tensors
          ):
              if not all(t.shape == tensors[0].shape for t in tensors):
                  raise TypeError(
                      "All input SparseTensors to Pack must be same shape."
                  )
              is_sparse = True
              tensors = (
                  [t.indices for t in tensors]
                  + [t.values for t in tensors]
                  + [
                      ops.convert_to_tensor(t.shape, dtype=dtypes.int64)
                      for t in tensors
                  ]
              )
          elif any(
              isinstance(t, sparse_tensor.SparseTensor) for t in tensors
          ):
              raise TypeError("Cannot Pack SparseTensors with Tensors.")
          else:
              is_sparse = False
          try:
              return _pywrap_dtensor_device.Pack(
                  context.context()._handle,  # pylint: disable=protected-access
                  tensors,
                  layout.to_string(),
                  self._device_info,
                  is_sparse,
              )
          except (
              core._NotOkStatusException
          ) as e:  # pylint: disable=protected-access
              raise core._status_to_exception(e) from None
  
imports: import contextlib
  import logging
  import threading
  from typing import Any, List, Sequence, Set
  import numpy
  from tensorflow.core.framework import attr_value_pb2
  from tensorflow.dtensor.python import config
  from tensorflow.dtensor.python import layout
  from tensorflow.python import _pywrap_dtensor_device
  from tensorflow.python.eager import context
  from tensorflow.python.eager import core
  from tensorflow.python.framework import device
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import sparse_tensor
  from tensorflow.python.framework import tensor_util
  from tensorflow.python.util import _pywrap_utils
label_desc: Use image node_id 5 for calling the DTensorDevice obj's underlying member method code with example usage: obj.pack(tensors, layout) and returns: _pywrap_dtensor_device