class_docstr: [`FlaxSpeechEncoderDecoderModel`] is a generic model class that will be instantiated as a transformer architecture
  with the module (flax.nn.Module) of one of the base model classes of the library as encoder module and another one
  as decoder module when created with the :meth*~transformers.FlaxAutoModel.from_pretrained* class method for the
  encoder and :meth*~transformers.FlaxAutoModelForCausalLM.from_pretrained* class method for the decoder.
class_docstr_tok: ["[","`","FlaxSpeechEncoderDecoderModel","`","]","is","a","generic","model","class","that","will","be","instantiated","as","a","transformer","architecture","with","the","module","(","flax.nn.Module",")","of","one","of","the","base","model","classes","of","the","library","as","encoder","module","and","another","one","as","decoder","module","when","created","with","the",":","meth","*","~transformers.FlaxAutoModel.from_pretrained","*","class","method","for","the","encoder","and",":","meth","*","~transformers.FlaxAutoModelForCausalLM.from_pretrained","*","class","method","for","the","decoder","."]
code: def prepare_inputs_for_generation(
      self,
      decoder_input_ids,
      max_length,
      attention_mask: Optional[jax.Array] = None,
      decoder_attention_mask: Optional[jax.Array] = None,
      encoder_outputs=None,
      **kwargs,
  ):
      # initializing the cache
      batch_size, seq_length = decoder_input_ids.shape
  
      past_key_values = self.init_cache(
          batch_size, max_length, encoder_outputs
      )
      # Note that usually one would have to put 0's in the attention_mask for x > input.shape[-1] and x < cache_length.
      # But since the decoder uses a causal mask, those positions are masked anyways.
      # Thus we can create a single static attention_mask here, which is more efficient for compilation
      extended_attention_mask = jnp.ones(
          (batch_size, max_length), dtype="i4"
      )
      if decoder_attention_mask is not None:
          decoder_position_ids = (
              decoder_attention_mask.cumsum(axis=-1) - 1
          )
          extended_attention_mask = lax.dynamic_update_slice(
              extended_attention_mask, decoder_attention_mask, (0, 0)
          )
      else:
          decoder_position_ids = jnp.broadcast_to(
              jnp.arange(seq_length, dtype="i4")[None, :],
              (batch_size, seq_length),
          )
  
      return {
          "past_key_values": past_key_values,
          "encoder_outputs": encoder_outputs,
          "encoder_attention_mask": attention_mask,
          "decoder_attention_mask": extended_attention_mask,
          "decoder_position_ids": decoder_position_ids,
      }
  
imports: import os
  from typing import Optional, Tuple, Union
  import flax.linen
  import jax
  import jax.numpy
  from flax.core.frozen_dict import FrozenDict, freeze, unfreeze
  from flax.traverse_util import flatten_dict, unflatten_dict
  from jax import lax
  from jax.random import PRNGKey
  from ...modeling_flax_outputs import FlaxBaseModelOutput, FlaxCausalLMOutputWithCrossAttentions, FlaxSeq2SeqLMOutput
  from ...modeling_flax_utils import FlaxPreTrainedModel
  from ...utils import add_start_docstrings, add_start_docstrings_to_model_forward, logging, replace_return_docstrings
  from ..auto.configuration_auto import AutoConfig
  from ..auto.modeling_flax_auto import FlaxAutoModel, FlaxAutoModelForCausalLM
  from .configuration_speech_encoder_decoder import SpeechEncoderDecoderConfig
label_desc: Use image node_id 8 for calling the FlaxSpeechEncoderDecoderModel obj's underlying member method code with example usage: obj.prepare_inputs_for_generation(decoder_input_ids, max_length, attention_mask, decoder_attention_mask, encoder_outputs) and returns: dict