calling Model in a loop would leak memory
@alerem18 Could you please provide the complete standalone code to replicate the [issue](https://colab.research.google.com/gist/sushreebarsa/1312d871663ec6136f188bc447d4b939/61942.ipynb) reported?
Thank you! https://keras.io/examples/nlp/neural_machine_translation_with_transformer/

in decoder_sequence will there be any solution or i should wait for you to reply once a month?
this is why people prefer pytorch over tensorflow @alerem18 I tried to replicate the issue on colab. https://keras.io/examples/nlp/neural_machine_translation_with_transformer/ is working fine in [colab](https://colab.research.google.com/gist/sushreebarsa/e8ca05c13b4748b40911c8c00a86a7bc/neural_machine_translation_with_transformer.ipynb#scrollTo=7Wz8hlIULZul) . Please let me know if i have missed something to replicate the reported error. Have you tried to use the GPU for this issue and let me know if the memory leak would be there? Thank you! > @alerem18 I tried to replicate the issue on colab. https://keras.io/examples/nlp/neural_machine_translation_with_transformer/ is working fine in [colab](https://colab.research.google.com/gist/sushreebarsa/e8ca05c13b4748b40911c8c00a86a7bc/neural_machine_translation_with_transformer.ipynb#scrollTo=7Wz8hlIULZul) . Please let me know if i have missed something to replicate the reported error. Have you tried to use the GPU for this issue and let me know if the memory leak would be there? Thank you!

i've not tested it on gpu, but i have memory issues when translating a lot of texts, in a loop
instead of eng_vectorization use input_vectorization, for spa_vectorization use output_vectorization

copy paste the code from the keras directly don't include my code @sachinprasadhs same issue on this but i didn't use @tf.function in translator, so i don't know if it's related to that
https://www.tensorflow.org/text/tutorials/transformer is there any damn solution for this or not?
### Issue type

Bug

### Have you reproduced the bug with TensorFlow Nightly?

No

### Source

source

### TensorFlow version

tf2.13.0

### Custom code

Yes

### OS platform and distribution

Windows Server 2019

### Mobile device

_No response_

### Python version

_No response_

### Bazel version

_No response_

### GCC/compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

there is a transformer model when i try to decode messages, translate input sentence to target sentence i get memory blow up, memory is good when i use transformer.fit(), but in a loop like below it blows up memory, tf.keras.backend.clear_session() does’t help, also accuracy decrease when i use that, gc.collect() doesn’t work also
here is my code

```python
def decode_sequence(input_sentence):
    tokenized_input_sentence = input_vectorization([input_sentence])
    decoded_sentence = START_TOKEN
    for i in tf.range(max_decoded_sentence_length):
        tokenized_target_sentence = output_vectorization([decoded_sentence])#[:, :-1]
        
        predictions = transformer([tokenized_input_sentence, tokenized_target_sentence])
        
        
        sampled_token_index = np.argmax(predictions[0, i, :])
        sampled_token = output_index_lookup[sampled_token_index]
        decoded_sentence += sampled_token

        if sampled_token == END_TOKEN:
            break
    
   
    gc.collect()
    return decoded_sentence

from tqdm import tqdm
def overall_accuracy(pairs):
    corrects = 0
    inputs = pairs[2739:]
    iter = tqdm(inputs)
    for i, pair in enumerate(iter):
        input_text = pair[0]
        target = pair[1]
        predicted = decode_sequence(input_text)
        #guess = '✓' if predicted == target else '✗'
        #print('Sample Number : ', i, 'Predicted : ', predicted, 'Real : ', target, guess)
        if predicted == target:
            corrects += 1
        iter.set_postfix(corrects=corrects, accuracy=corrects / (i + 1))
    
    return corrects / len(inputs)

print("Overall Acurracy : ", overall_accuracy(test_pairs))```

### Standalone code to reproduce the issue

```shell
calling model in a loop
```


### Relevant log output

_No response_