code: def create_layer_for_inference(layer: _TrainingWrapper, algorithm):
      """Internal API to create layer for inference with weight compression."""
      # TODO(tfmot): move these checks to public API for
      # visibility.
      if not isinstance(algorithm, object):
          raise ValueError(
              "`_create_layer_for_inference` requires `algorithm` "
              "to be an instantiated object, as opposed "
              "to the class itself."
          )
  
      if not layer.built:
          raise ValueError(
              "`_create_layer_for_inference` requires `layer` to be built."
          )
  
      # Process layer.
      nested_layer = layer.layer
      input_shape = layer.input_shape
  
      # Construct map from attribute (e.g. 'kernel') to tensor versions of
      # variables used during training.
      compressible_training_tensors = {}
      for attr, weights in layer.training_weights.items():
          compressible_training_tensors[attr] = [
              w.read_value() for w in weights
          ]
  
      # Process nested layer.
      #
      # TODO(tfmot): same TODOs as in _create_layer_for_training.
      cloned_layer = nested_layer.__class__.from_config(
          nested_layer.get_config()
      )
  
      layer_for_inference = _InferenceWrapper(
          cloned_layer, algorithm, compressible_training_tensors
      )
      layer_for_inference.build(input_shape)
  
      if layer.get_weights():
          # Set weights of layer for inference according to what was trained.
          inference_weights = _map_to_inference_weights(
              layer.get_weights(),
              algorithm,
              compressible_training_tensors,
          )
          layer_for_inference.set_weights(inference_weights)
  
      return layer_for_inference
  
imports: from typing import List, Mapping
  import tensorflow
label_desc: Use image node_id 6 for calling a global function with example usage: create_layer_for_inference(layer, algorithm) and returns: layer_for_inference