Hi, in the first example the source text ids are also passed to the decoder, which they should not. When generating, the decoder sequence should first start with the decoder_start_token and not from the source ids.  So when generating for the first step  pass the encoder_hidden_states and decoder_start_token_id as the first id. So the correct usage would be
enc = tokenizer(['translate English to French: I was a victim of a series of accidents.'], return_tensors="pt")
input_ids = enc['input_ids']
encoded_embeddings = encoder(input_ids)[0]

# decoder inputs should start from decoder_input_ids,
# for T5 pad_token_id is the deocder_start_token
generated = torch.tensor([[tokenizer.pad_token_id]])

for _ in range(16):
  decoder_output = decoder(input_ids=generated, encoder_hidden_states=encoded_embeddings)[0]
  logits = lm_head(decoder_output)
  next_token_logits = logits[0, -1, :]
  next_token = torch.argmax(next_token_logits).unsqueeze(0)
  generated = torch.cat((generated, next_token.unsqueeze(0)), dim=1)

tokenizer.decode(generated[0])

which generates J'ai été victime d'une série d'accident.
Also when  passing padded text, we should also pass attention_mask so the pad tokens won’t be attended. The tokenizer returns attention_mask  along with the input_ids.
And to create tensors for the tokenized ids, pass the return_tensors argument to the tokenizer which will then return tensor instead of list depending on the value of return_tensor which is ‘pt’ for torch tensors, ‘tf’ for tf tensors. If you pass a list of strings, tokenizer will automatically batch them.