# Gorfoustral (2/3)

**Catégorie:** Intelligence Artificielle - **Difficulté:** Facile

**Description:**

<figure><img src="/files/GexyungToQskYzPeNQEU" alt=""><figcaption></figcaption></figure>

Solution:

Comme le [challenge précédent](/2025/404ctf-2025/intelligence-artificielle/gorfoustral-1-3.md), il faut laisser tourner le modèle quelques minutes afin d'avoir le flag en clair.

Voici le script utilisé pour résoudre ce chall :&#x20;

```python
import torch as t
from gorfougym import load_model

MODEL_PATH = "gorfoustral-1.1_300M.pt"      # modèle du challenge 2
DEVICE     = "cpu"                          # ou "cuda" si tu veux aller plus vite

# ──────────────────────────────────────────────────────────────────────────────
# 1) Chargement du modèle fine-tuné
# ──────────────────────────────────────────────────────────────────────────────
model = load_model(MODEL_PATH, device=DEVICE)
print("Modèle chargé → skip des deux derniers blocs…")

# ──────────────────────────────────────────────────────────────────────────────
# 2) On met tous les poids (attn et MLP) des 2 derniers blocs à zéro
#    → ils deviennent des identités et n'ajoutent plus de bruit
# ──────────────────────────────────────────────────────────────────────────────
def disable_block(block):
    with t.no_grad():
        for _, param in block.named_parameters():
            param.zero_()

disable_block(model.blocks[-1])   # dernier bloc
disable_block(model.blocks[-2])   # avant-dernier bloc

# ──────────────────────────────────────────────────────────────────────────────
# 3) Complétion deterministe du prompt "User: 404CTF{"
# ──────────────────────────────────────────────────────────────────────────────
prompt  = "User: 404CTF{"
tokens  = model.to_tokens(prompt)
# 100 tokens = largement assez pour le flag + "}\nAssistant: True"
out_tok = model.generate(tokens, max_new_tokens=100, temperature=0.0)
out_txt = model.to_string(out_tok[0])

# ──────────────────────────────────────────────────────────────────────────────
# 4) Extraction du flag entre "404CTF{" et "}"
# ──────────────────────────────────────────────────────────────────────────────
start = out_txt.find("404CTF{")
end   = out_txt.find("}", start)
if start != -1 and end != -1:
    flag = out_txt[start:end + 1]
    print(flag)
else:
    raise ValueError("Flag introuvable - essaie d’augmenter max_new_tokens.")
```

Après quelques minutes (ou secondes selon votre machine), le résultat s'affiche en clair :&#x20;

<figure><img src="/files/ZxOiI2gyjLskL7OULn1C" alt=""><figcaption></figcaption></figure>

<details>

<summary>🚩FLAG</summary>

`404CTF{superbe_methode_avancee_de_desapprentisage}`

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://writeups.ayweth20.com/2025/404ctf-2025/intelligence-artificielle/gorfoustral-2-3.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
