> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreweave.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Runs

> Initialisez et gérez les runs W&B pour organiser vos expériences et suivre votre travail.

Initialisez et gérez des runs W\&B pour organiser vos expériences et suivre votre travail.

<h2 id="create-an-experiment">
  Créer une expérience
</h2>

```python theme={"system"}
"""
Create an experiment in W&B. If the project does not exist, W&B creates it.

Note that this file only initializes the experiment; you can add code to log metrics,
artifacts, etc., within the `with` block.
"""
import wandb

# Initialiser un run W&B
with wandb.init(project="<project>") as run:
    # Placez ici le code de votre expérience
    pass
```

<h2 id="fork-an-existing-run-from-a-specific-step">
  Créer un fork d’un run existant à partir d’un step donné
</h2>

```python theme={"system"}
"""Fork an existing W&B run from a specific step."""

import wandb

# Initialiser un run qui sera forké par la suite
with wandb.init(project="<project>", entity="<entity>") as original_run:
    # Placez ici le code d’entraînement et de journalisation.
    pass

# Forker le run à partir d’un step précis. Dans cet exemple, le fork part du step 200. Vous pouvez modifier la valeur du step selon vos besoins.
with wandb.init(project="<project>",entity="<entity>", fork_from=f"{original_run.id}?_step=200") as forked_run:
    # Placez ici le code d’entraînement et de journalisation.
    pass
```

<h2 id="initialize-a-run">
  Initialiser un run
</h2>

```python theme={"system"}
"""
Initializes a W&B run.

W&B automatically creates the project if it does not exist. Note that this
file only initializes the experiment; you can add code to log metrics,
artifacts, etc., within the `with` block.
"""
import wandb

# Notez l’utilisation de l’instruction `with`, qui garantit une gestion correcte des ressources.
with wandb.init(project="<project>") as run:
    # Placez ici le code d’entraînement et de journalisation
    pass
```

<h2 id="set-resume-behaviour-for-a-run-if-it-is-paused-stops-or-fails">
  Définir le comportement de reprise d’un run en cas de pause, d’arrêt ou d’échec
</h2>

```python theme={"system"}
"""
Set resume behaviour for a run if it is paused, stops, or fails. 

This is useful for long-running experiments that may be interrupted. See
reference documentation for wandb.init(resume=) for a list of all resume options.
"""
import wandb

# Initialiser un run W&B avec un comportement de reprise
with wandb.init(project="<project>", resume="<resume_option>") as run:
    # Placez ici votre code d’entraînement et de journalisation
    pass
```

<h2 id="rewind-a-run-to-modify-the-history-of-a-run">
  Rembobiner un run pour modifier son historique
</h2>

```python theme={"system"}
"""
Rewind a run to modify the history of a run.

Specify the run ID and step to rewind to with the `resume_from` parameter in `wandb.init()`.
"""
import wandb
import math

# Initialiser un run et journaliser quelques métriques
with wandb.init(project="<project>", entity="<entity>") as run:
    # Placer ici le code d’entraînement et de journalisation
    pass

run_ID = "<run_id>" # Remplacer par l’ID du run d’origine
step = int("<step>") # Indiquer le step jusqu’auquel rembobiner

# Démarrer un nouveau run qui reprend à partir du step indiqué du run d’origine
with wandb.init(project="<project>", entity="<entity>", resume_from=f"{run_ID}?_step={step}") as run:
    # Placer ici le code d’entraînement et de journalisation
    pass    
```

<h2 id="add-one-or-more-tags-to-a-run">
  Ajouter un ou plusieurs tags à un run
</h2>

```python theme={"system"}
"""
Add one or more tags to a run.
"""
import wandb

with wandb.init(entity="<entity>", project="<project>", tags=["<tag1>", "<tag2>"]) as run:
    # Placez ici le code d’entraînement et de journalisation
    pass
```

<h2 id="add-one-or-more-runs-to-a-group">
  Ajouter un ou plusieurs runs à un groupe
</h2>

```python theme={"system"}
"""
Add one or more runs to a group.

Pass the name of your group as an argument to the `group` parameter when you
initialize a run with `wandb.init(group="")`.
"""
import wandb

entity = "<entity>"
project = "<project>"

# Le code suivant crée 3 groupes de runs, contenant chacun 3 runs. 
for group in ["<GroupA>", "<GroupB>", "<GroupC>"]: # Remplacez par les noms de groupes de votre choix
    # Simuler la création de trois runs par groupe.
    for i in range(3):
        with wandb.init(entity=entity, project=project, group=group, name=f"{group}_run_{i}") as run:
            # Placez ici votre code d’entraînement et de journalisation
            pass    
```

<h2 id="organize-runs-by-their-job-type">
  Organiser les runs par type de job
</h2>

```python theme={"system"}
"""
Organize runs by their job type.

Add a job type to a run by passing the `job_type` parameter to `wandb.init(job_type="")`.
"""
import wandb

entity = "<entity>"
project = "<project>"

# Crée des runs et les organise par type de job.
for job_type in ["<JobType1>", "<JobType2>"]: # Remplacez par les noms de vos types de job
    # Simule la création de deux runs par type de job.
    for i in range(2):
        with wandb.init(entity=entity, project=project, job_type=job_type, name=f"{job_type}_run_{i}") as run:
            # Placez ici votre code d’entraînement et de journalisation
            pass    
```

<h2 id="add-one-or-more-tags-to-an-active-run">
  Ajouter un ou plusieurs tags à un run actif
</h2>

```python theme={"system"}
"""
Add one or more tags to an active run.

A run object's `tags` property is a tuple. To add a new tag to an existing run,
update the `tags` property with a new tuple that includes the existing tags and the new tag(s).
"""

import wandb

with wandb.init(entity="<entity>", project="<project>", tags=["<tag1>", "<tag2>"]) as run:
    # Placez ici votre code d’entraînement et de journalisation

    # Ajoutez un nouveau tag aux tags existants en créant un nouveau tuple qui contient les tags existants et le nouveau tag.
    run.tags += ("<tag3>",)
```

<h2 id="add-one-or-more-tags-to-previously-saved-runs">
  Ajouter un ou plusieurs tags à des runs déjà enregistrés
</h2>

```python theme={"system"}
"""
Add one or more tags to previously saved runs.

Use the Public API to update tags on stored data after the run has finished or
when you are working outside the run process. This is useful when you need to
organize or categorize runs retroactively.

To add a new tag to a run, update the `tags` property with a new list that
includes the existing tags and the new tags. The run's path consists of
`entity/project/run_id`. After updating the tags, you must call the run's
`update()` method to save the changes.
"""
import wandb

entity = "<entity>"
project = "<project>"
run_id = "<run-id>"  # Remplacez par l’ID du run à mettre à jour

# Le chemin est de la forme entity/project/run_id
with wandb.Api().run(f"{entity}/{project}/{run_id}") as run:
  run.tags.append("<tag>")
  run.update()
```
