corrige ce code qui utilise modal :
import time
import modal
from modal import App, Image, NetworkFileSystem, wsgi_app,Volume
import pathlib
import modal




dockerhub_image = Image.from_registry(
    "tensorflow/tensorflow:2.12.0-gpu",
).pip_install("protobuf==3.20.*","datasets","tensorflow_text",'numpy',"tensorflow_datasets")

app = App(
    "example-tensorflow-tutorial", image=dockerhub_image
)  # Note: prior to April 2024, "app" was called "stub"

volume = modal.Volume.from_name("mains")

pen = pathlib.Path("/root/foo/en_vocab.txt")
pfr = pathlib.Path("/root/foo/fr_vocab.txt")


vol = Volume.from_name("mains", create_if_missing=True)

@app.function(volumes={"/root/foo": volume},timeout=1000,memory=8000,cpu=2.0, gpu="T4")
def download():
    import datasets
    from datasets import load_dataset
    import tensorflow_text as tf_text
    import tensorflow_datasets as tfds
    import numpy as np
    import tensorflow as tf
    from datasets import load_dataset
    dataset = load_dataset("Helsinki-NLP/opus-100", "en-fr")
    data = dataset["train"]
    val = dataset["validation"]
    french_sentences = [example["fr"] for example in data["translation"]]
    english_sentences = [example["en"] for example in data["translation"]]
    vfrench_sentences = [example["fr"] for example in val["translation"]]
    venglish_sentences = [example["en"] for example in val["translation"]]
    dataset = tf.data.Dataset.from_tensor_slices((french_sentences, english_sentences))
    vdataset = tf.data.Dataset.from_tensor_slices((vfrench_sentences, venglish_sentences))
    french_sentences_decoded = []
    english_sentences_decoded = []

    vfrench_sentences_decoded = []
    venglish_sentences_decoded = []

    for french_sentence, english_sentence in dataset.take(len(french_sentences)):
        french_sentences_decoded.append("b '"+french_sentence.numpy().decode('utf-8'))
        english_sentences_decoded.append("b '"+english_sentence.numpy().decode('utf-8'))


    for french_sentence, english_sentence in dataset.take(len(vfrench_sentences)):
        vfrench_sentences_decoded.append("b '"+french_sentence.numpy().decode('utf-8'))
        venglish_sentences_decoded.append("b '"+english_sentence.numpy().decode('utf-8'))


    print("Nombre de phrases en français :", len(french_sentences_decoded))
    print("Nombre de phrases en anglais :", len(english_sentences_decoded))
    print("Nombre de phrases en français pour la validation :", len(vfrench_sentences_decoded))
    print("Nombre de phrases en anglais pour la validation :", len(venglish_sentences_decoded))
    volume.commit() 
    return french_sentences_decoded,english_sentences_decoded, vfrench_sentences_decoded, venglish_sentences_decoded
    
@app.function(volumes={"/root/foo": volume},timeout=10000,memory=8000,cpu=1.0,gpu= "T4")

def init(french_sentences_decoded,english_sentences_decoded, vfrench_sentences_decoded, venglish_sentences_decoded):
    volume.reload()
    print("oais")
    import datasets
    from datasets import load_dataset
    import tensorflow_text as tf_text
    import tensorflow_datasets as tfds
    import numpy as np
    import tensorflow as tf
    from datasets import load_dataset
    from tensorflow_text.tools.wordpiece_vocab import bert_vocab_from_dataset as bert_vocab
    train_fr = french_sentences
    train_en = english_sentences
    
    print("YES")
    bert_tokenizer_params = dict(lower_case=False)
    reserved_tokens = ["[START]","[END]","[PAD]","[UNK]"]

    bert_vocab_args = {
        'vocab_size': 8000,
        'reserved_tokens': reserved_tokens,
        'bert_tokenizer_params': bert_tokenizer_params,
        'learn_params': {},
    }
    return bert_vocab_args,train_en,train_fr


@app.function(gpu="A100",volumes={"/root/foo": volume},timeout=10000,memory=40000,cpu=16.0)
def en(bert_vocab_args,french_sentences_decoded,english_sentences_decoded, vfrench_sentences_decoded, venglish_sentences_decoded,train_en,train_fr):
        import datasets
        from datasets import load_dataset
        import tensorflow_text as tf_text
        import tensorflow_datasets as tfds
        import numpy as np
        import tensorflow as tf
        from datasets import load_dataset
        from tensorflow_text.tools.wordpiece_vocab import bert_vocab_from_dataset as bert_vocab

        en_vocab = bert_vocab.bert_vocab_from_dataset(
            tf.data.Dataset.from_tensor_slices(english_sentences).batch(2000).prefetch(2),
            **bert_vocab_args
        )
        print("fin de en VOCAB")
        with open("en_vocab.txt", 'w', encoding='utf-8') as f:
            for token in en_vocab:
                print(token, file=f)
        volume.commit()
        return en_vocab
@app.function(volumes={"/root/foo": volume},timeout=1000,memory=40000,cpu=1.0, gpu = 'T4')
def g(reload: bool = False):
        if reload:
            volume.reload()  # Fetch latest changes
        if pen.exists():
            print(f"{pen=} contains '{pen.read_text()}'")
        else:
            print(f"{pen=} does not exist!")
    
@app.function(gpu="A100",volumes={"/root/foo": volume},timeout=10000,memory=40000,cpu=16.0)
def fr(bert_vocab_args,french_sentences_decoded,english_sentences_decoded, vfrench_sentences_decoded, venglish_sentences_decoded,train_en,train_fr):
    import datasets
    from datasets import load_dataset
    import tensorflow_text as tf_text
    import tensorflow_datasets as tfds
    import numpy as np
    import tensorflow as tf
    from datasets import load_dataset
    from tensorflow_text.tools.wordpiece_vocab import bert_vocab_from_dataset as bert_vocab
    fr_vocab = bert_vocab.bert_vocab_from_dataset(
                tf.data.Dataset.from_tensor_slices(french_sentences).batch(2000).prefetch(2),
                **bert_vocab_args
            )
    print("fin de FR VOCAB")
    with open("fr_vocab.txt", 'w', encoding='utf-8') as f:
            for token in fr_vocab:
                print(token, file=f)
    volume.commit()
    return fr_vocab


@app.function(volumes={"/root/foo": volume},timeout=1000,memory=40000,cpu=1.0, gpu = 'T4')
def g2(reload: bool = False):
        if reload:
            volume.reload()  # Fetch latest changes
        if pen.exists():
            print(f"{pfr=} contains '{pen.read_text()}'")
        else:
            print(f"{pfr=} does not exist!")
    

@app.local_entrypoint()

def main():
    download.remote()
    init.remote(french_sentences_decoded,english_sentences_decoded, vfrench_sentences_decoded, venglish_sentences_decoded)
    g.remote()
    en.remote(bert_vocab_args,french_sentences_decoded,english_sentences_decoded, vfrench_sentences_decoded, venglish_sentences_decoded,train_en,train_fr)
    g.remote(reload=False)  
    g.remote(reload=True)   
    
    g2.remote()
    fr.remote(bert_vocab_args,french_sentences_decoded,english_sentences_decoded, vfrench_sentences_decoded, venglish_sentences_decoded,train_en,train_fr)
    g2.remote(reload=False)  # 3. reuses container for `g`, no reload
    g2.remote(reload=True)   # 4. reuses container, but reloads to see file.