Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Astar Island — Viking Civilisation Prediction

AI-agent for NM i AI. Predikerer terreng-sannsynligheter pa et 40x40 grid etter 50 ar med vikingsivilisasjon-simulering.

Hurtigstart

Installer avhengigheter:

pip install -r requirements.txt
pip install torch

Lag token-fil:

Windows (PowerShell):

Set-Content -Path my_token.txt -Value "DIN_JWT_TOKEN"

Linux/macOS:

echo "DIN_JWT_TOKEN" > my_token.txt

Start agent:

python runner.py --token-file my_token.txt

Hent JWT-token: app.ainm.no -> F12 -> Application -> Cookies -> access_token

VIKTIG: ALDRI commit my_token.txt til git!

Anbefalt oppsett: to terminaler

Kjor begge samtidig for best resultat:

Terminal Kommando Rolle
1 python continuous_train.py --token-file my_token.txt Trener modellen non-stop i bakgrunnen
2 python runner.py --token-file my_token.txt --use-llm Samler data, submitter, bruker LLM

continuous_train.py forbedrer model.pt kontinuerlig. runner.py bruker siste model.pt ved submission.

runner.py — Hovedloop

Gjor ALT automatisk i en evig loop:

SYKLUS
  |
  +-- FASE 1: SAMLE DATA
  |   Henter ground truth fra avsluttede runder
  |
  +-- FASE 2: TRENE
  |   Trener U-Net modell til val_loss < threshold
  |
  +-- FASE 3: SUBMITTE (med IDUN LLM hvis --use-llm)
  |   Simulerer + submitter prediksjoner for aktiv runde
  |   Bruker trent modell + observasjoner + LLM-analyse
  |
  +-- FASE 4: EVALUERE
  |   Sjekker scores og ranking
  |
  +-- VENTER 5 MIN -> neste syklus

Flagg

Flagg Default Beskrivelse
--threshold 0.5 Val loss mal. Lavere = strengere modell for submission
--max-epochs 500 Maks treningsepoker per syklus
--use-llm av Bruk IDUN LLM til a analysere observasjoner (krever NTNU VPN)
--dirichlet-prior 3.0 Prior-styrke i Bayes blending (hoyere = mer tillit til modell)
--max-ensemble-models 5 Maks antall modeller brukt i ensemble/TTA
--tta-modes identity,rot90,rot270,flip_h TTA-transformasjoner for inferens
--model-sync-from av Hent model.pt fra delt mappe/fil for hver submit-syklus

For --use-llm ma du sette API-nokkel i miljoet:

Windows (PowerShell):

$env:IDUN_API_KEY="din_idun_nokkel"

Linux/macOS:

export IDUN_API_KEY="din_idun_nokkel"

Eksempel med algoritmetuning:

python runner.py --token-file my_token.txt --use-llm --dirichlet-prior 2.5 --max-ensemble-models 3 --tta-modes identity,rot90,flip_h

Presets (anbefalt)

Safe (mest stabil):

python runner.py --token-file my_token.txt --use-llm --dirichlet-prior 3.5 --max-ensemble-models 5 --tta-modes identity,rot90,rot270,flip_h
python continuous_train.py --token-file my_token.txt --target-loss 0.01 --epochs-per-cycle 120 --lr 0.0008 --weight-decay 0.0012 --dropout-enc2 0.25 --dropout-bottleneck 0.35 --mixup-prob 0.60 --feature-noise-std 0.015 --overfit-gap-threshold 0.02 --overfit-patience 10

Balanced (default for daglig bruk):

python runner.py --token-file my_token.txt --use-llm --dirichlet-prior 3.0 --max-ensemble-models 4 --tta-modes identity,rot90,rot270,flip_h
python continuous_train.py --token-file my_token.txt --target-loss 0.01 --epochs-per-cycle 220 --lr 0.0015 --weight-decay 0.0008 --dropout-enc2 0.15 --dropout-bottleneck 0.25 --mixup-prob 0.45 --feature-noise-std 0.01 --overfit-gap-threshold 0.025 --overfit-patience 20

Aggressive (når du vil presse score):

python runner.py --token-file my_token.txt --use-llm --dirichlet-prior 2.2 --max-ensemble-models 3 --tta-modes identity,rot90,flip_h
python continuous_train.py --token-file my_token.txt --target-loss 0.01 --epochs-per-cycle 260 --lr 0.0018 --weight-decay 0.0006 --dropout-enc2 0.12 --dropout-bottleneck 0.20 --mixup-prob 0.35 --feature-noise-std 0.008 --overfit-gap-threshold 0.03 --overfit-patience 24

To maskiner (PC + Cloud/Colab) som faktisk synker modell

Bruk en delt mappe (Google Drive / OneDrive / Dropbox) som begge maskiner ser.

Cloud/Colab (trening):

python continuous_train.py --token-file my_token.txt

Synk fra cloud til delt mappe etter trening (f.eks. i Colab):

cp model.pt /path/to/shared/model.pt

PC (spilling/submit):

python runner.py --token-file my_token.txt --use-llm --model-sync-from "/path/to/shared"

Runner henter da nyere model.pt fra delt mappe automatisk før submit.

Kommandoer mens den kjorer

Skriv direkte i terminalen:

Kommando Effekt
threshold 0.2 Krev bedre modell for submission
threshold 0.8 Slipp gjennom raskere
epochs 1000 Mer trening per syklus
train Tving ny trening na
submit Tving submission na
status Vis oversikt
quit Avslutt

continuous_train.py — Bakgrunnstrening

Kjorer trening i en evig loop, uavhengig av runner.py:

  1. Henter ny treningsdata fra API
  2. Trener modellen (med augmentation + early stopping)
  3. Lagrer beste modell til model.pt
  4. Venter pa mer data -> gjenta
python continuous_train.py --token-file my_token.txt --target-loss 0.01
Flagg Default Beskrivelse
--target-loss 0.01 Mal for val_loss
--epochs-per-cycle 220 Maks epoker per treningssyklus
--collect-interval 180 Sekunder mellom datainnsamling
--lr 0.0015 Learning rate
--weight-decay 0.0008 Regularisering
--patience 80 Early stopping uten forbedring
--min-delta 0.0005 Min forbedring for ny "best"
--top-k-checkpoints 3 Antall beste epoker som kan snittes
--dropout-enc2 0.15 Dropout i encoder-blokk 2
--dropout-bottleneck 0.25 Dropout i bottleneck
--mixup-prob 0.45 Sannsynlighet for mixup per batch
--mixup-alpha 0.30 Mixup-styrke
--feature-noise-std 0.01 Gaussisk stoy pa input-features
--overfit-gap-threshold 0.025 Stopper hvis val-train gap blir for stor
--overfit-patience 20 Antall epoker med stort gap for stopp

Eksempel ved tydelig overfitting (train mye lavere enn val):

python continuous_train.py --token-file my_token.txt --target-loss 0.01 --dropout-enc2 0.25 --dropout-bottleneck 0.35 --mixup-prob 0.60 --feature-noise-std 0.015 --overfit-gap-threshold 0.02 --overfit-patience 12

Google Cloud Shell

git clone <ditt-repo>
cd NMiAI
pip install requests numpy
pip install torch --index-url https://download.pytorch.org/whl/cpu
echo "DIN_JWT_TOKEN" > my_token.txt

# Kjor i tmux sa den overlever om du lukker fanen
tmux new -s train
python continuous_train.py --token-file my_token.txt
# Ctrl+B, D for a detache

tmux new -s runner
python runner.py --token-file my_token.txt --use-llm
# Ctrl+B, D for a detache

IDUN (NTNU HPC) — kjor trening med SLURM

Repoet har ferdig jobbfiler for IDUN-trening:

  • idun_train.slurm (selve GPU-jobben)
  • submit_idun_train.sh (enkel submit-wrapper)

Etter at du har SSH-et inn pa IDUN og cd-et inn i prosjektmappa:

chmod +x submit_idun_train.sh
mkdir -p logs
./submit_idun_train.sh my_token.txt

Sjekk status og logs:

squeue -u $USER
tail -f logs/idun_train_*.out

Tilpass trening via miljo-variabler ved submit:

TARGET_LOSS=0.010 EPOCHS_PER_CYCLE=260 NUM_FOLDS=5 COLLECT_INTERVAL=120 ./submit_idun_train.sh my_token.txt

Hvis du vil synke model.pt til delt sti fra IDUN:

SYNC_MODEL_TO=/path/to/shared/model.pt ./submit_idun_train.sh my_token.txt

Du kan ogsa submitte direkte uten wrapper:

sbatch --export=ALL,TOKEN_FILE=my_token.txt,TARGET_LOSS=0.010,EPOCHS_PER_CYCLE=220,NUM_FOLDS=5 idun_train.slurm

Kjore pa BADE PC og Cloud Shell

Ja! Begge kan kjore samtidig:

  • Begge samler data — ingen konflikt
  • Begge trener — hver maskin har sin egen model.pt
  • Begge submitter — siste submission per seed vinner
  • 50 queries per runde er DELT mellom alle klienter

Viktig: Kjor bare EN maskin med queries for a unnga konflikt.

Manuelle scripts

Windows (PowerShell):

$TOKEN = Get-Content my_token.txt -Raw
python solver.py --token $TOKEN
python collect_data.py --token $TOKEN
python train_model.py --epochs 200
python solver.py --token $TOKEN --model model.pt

Linux/macOS:

python solver.py --token $(cat my_token.txt)           # Submit prediksjoner
python agent.py --token $(cat my_token.txt)             # LLM-drevet solver
python collect_data.py --token $(cat my_token.txt)      # Samle treningsdata
python train_model.py --epochs 200                       # Tren modell
python solver.py --token $(cat my_token.txt) --model model.pt  # Submit med modell

Filstruktur

NMiAI/
  runner.py              # Hovedloop: data + trening + submit + LLM
  continuous_train.py    # Kontinuerlig trening i bakgrunnen
  solver.py              # Manuell: observer + prediker + submit
  agent.py               # Manuell: LLM-drevet solver
  collect_data.py        # Manuell: hent treningsdata
  train_model.py         # Manuell: tren U-Net modell
  model.pt               # Trent modell (genereres automatisk)
  training_data/         # Treningsdata (.npz filer)
  my_token.txt           # JWT token (IKKE commit!)

.gitignore

model.pt
training_data/
my_token.txt
venv*/
__pycache__/

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages