Upload 9 files
Browse files- scripts/GenerateText.ps1 +21 -0
- scripts/Menu.ps1 +36 -0
- scripts/PublishToHuggingFace.ps1 +191 -0
- scripts/README.md +2 -0
- scripts/TrainAndLearn.ps1 +38 -0
- scripts/TrainEvaluate.ps1 +36 -0
- scripts/infer_model.ps1 +13 -0
- scripts/install.sh +2 -0
- scripts/train_model.ps1 +25 -0
scripts/GenerateText.ps1
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
param(
|
| 2 |
+
[string]$Prompt = "Programación",
|
| 3 |
+
[string]$ModelPath = "artifacts/checkpoints/marslm-final.pt",
|
| 4 |
+
[string]$ConfigPath = "artifacts/checkpoints/config.json",
|
| 5 |
+
[string]$TokenizerPath = "artifacts/tokenizer/marslm.json",
|
| 6 |
+
[int]$MaxNewTokens = 80,
|
| 7 |
+
[double]$Temperature = 0.2
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
$ErrorActionPreference = "Stop"
|
| 11 |
+
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
|
| 12 |
+
$repoRoot = Resolve-Path (Join-Path $scriptPath "..")
|
| 13 |
+
Set-Location $repoRoot
|
| 14 |
+
|
| 15 |
+
Write-Host "========================================" -ForegroundColor Cyan
|
| 16 |
+
Write-Host "MarsLM - Generar texto" -ForegroundColor Cyan
|
| 17 |
+
Write-Host "========================================" -ForegroundColor Cyan
|
| 18 |
+
Write-Host ""
|
| 19 |
+
Write-Host "Prompt: $Prompt" -ForegroundColor Yellow
|
| 20 |
+
|
| 21 |
+
python inference/generate.py --model-path $ModelPath --config $ConfigPath --tokenizer-model $TokenizerPath --prompt $Prompt --max-new-tokens $MaxNewTokens --temperature $Temperature
|
scripts/Menu.ps1
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
$ErrorActionPreference = "Stop"
|
| 2 |
+
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
|
| 3 |
+
$repoRoot = Resolve-Path (Join-Path $scriptPath "..")
|
| 4 |
+
Set-Location $repoRoot
|
| 5 |
+
|
| 6 |
+
while ($true) {
|
| 7 |
+
Write-Host ""
|
| 8 |
+
Write-Host "========================================" -ForegroundColor Cyan
|
| 9 |
+
Write-Host "MarsLM - Menú principal" -ForegroundColor Cyan
|
| 10 |
+
Write-Host "========================================" -ForegroundColor Cyan
|
| 11 |
+
Write-Host "1. Entrenar modelo" -ForegroundColor Yellow
|
| 12 |
+
Write-Host "2. Generar texto" -ForegroundColor Yellow
|
| 13 |
+
Write-Host "3. Ver checkpoints" -ForegroundColor Yellow
|
| 14 |
+
Write-Host "4. Salir" -ForegroundColor Yellow
|
| 15 |
+
$choice = Read-Host "Elige una opción"
|
| 16 |
+
|
| 17 |
+
switch ($choice) {
|
| 18 |
+
"1" {
|
| 19 |
+
$epochs = Read-Host "Número de epochs (por ejemplo 5)"
|
| 20 |
+
powershell -ExecutionPolicy Bypass -File .\scripts\TrainEvaluate.ps1 -Epochs $epochs
|
| 21 |
+
}
|
| 22 |
+
"2" {
|
| 23 |
+
$prompt = Read-Host "Escribe el prompt"
|
| 24 |
+
powershell -ExecutionPolicy Bypass -File .\scripts\GenerateText.ps1 -Prompt $prompt -MaxNewTokens 60 -Temperature 0.2
|
| 25 |
+
}
|
| 26 |
+
"3" {
|
| 27 |
+
Get-ChildItem .\artifacts\checkpoints | Select-Object Name, Length | Format-Table -AutoSize
|
| 28 |
+
}
|
| 29 |
+
"4" {
|
| 30 |
+
break
|
| 31 |
+
}
|
| 32 |
+
default {
|
| 33 |
+
Write-Host "Opción no válida" -ForegroundColor Red
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
}
|
scripts/PublishToHuggingFace.ps1
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
param(
|
| 2 |
+
[Parameter(Mandatory = $true)]
|
| 3 |
+
[string]$RepoId,
|
| 4 |
+
[string]$Token,
|
| 5 |
+
[switch]$Private,
|
| 6 |
+
[switch]$DryRun
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
$ErrorActionPreference = "Stop"
|
| 10 |
+
|
| 11 |
+
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
|
| 12 |
+
$repoRoot = Resolve-Path (Join-Path $scriptPath "..")
|
| 13 |
+
Set-Location $repoRoot
|
| 14 |
+
|
| 15 |
+
$checkpointPath = Join-Path $repoRoot "artifacts/checkpoints/marslm-final.pt"
|
| 16 |
+
$configPath = Join-Path $repoRoot "artifacts/checkpoints/config.json"
|
| 17 |
+
$tokenizerPath = Join-Path $repoRoot "artifacts/tokenizer/marslm.json"
|
| 18 |
+
|
| 19 |
+
$requiredFiles = @(
|
| 20 |
+
$checkpointPath,
|
| 21 |
+
$configPath,
|
| 22 |
+
$tokenizerPath
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
foreach ($file in $requiredFiles) {
|
| 26 |
+
if (-not (Test-Path $file)) {
|
| 27 |
+
throw "No se encontró el archivo requerido: $file"
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
Write-Host "========================================" -ForegroundColor Cyan
|
| 32 |
+
Write-Host "Publicando MarsLM en Hugging Face Hub" -ForegroundColor Cyan
|
| 33 |
+
Write-Host "========================================" -ForegroundColor Cyan
|
| 34 |
+
Write-Host "Repo: $RepoId" -ForegroundColor Green
|
| 35 |
+
Write-Host ""
|
| 36 |
+
|
| 37 |
+
if ($DryRun) {
|
| 38 |
+
Write-Host "Modo de prueba: no se subirá nada." -ForegroundColor Yellow
|
| 39 |
+
Write-Host "Archivos que se publicarían:" -ForegroundColor Yellow
|
| 40 |
+
|
| 41 |
+
foreach ($file in $requiredFiles) {
|
| 42 |
+
Write-Host " - $file" -ForegroundColor Yellow
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
return
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
# Buscar token
|
| 49 |
+
$token = $Token
|
| 50 |
+
|
| 51 |
+
if (-not $token) {
|
| 52 |
+
$token = $env:HF_TOKEN
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
# Token antiguo
|
| 56 |
+
if (-not $token) {
|
| 57 |
+
$tokenFile = Join-Path $HOME ".huggingface\token"
|
| 58 |
+
|
| 59 |
+
if (Test-Path $tokenFile) {
|
| 60 |
+
$token = (Get-Content $tokenFile -Raw).Trim()
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
# Token moderno hf auth login
|
| 65 |
+
if (-not $token) {
|
| 66 |
+
|
| 67 |
+
$hfTokenPath = Join-Path $HOME ".cache\huggingface\token"
|
| 68 |
+
|
| 69 |
+
if (Test-Path $hfTokenPath) {
|
| 70 |
+
$token = (Get-Content $hfTokenPath -Raw).Trim()
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
# Pedir token manualmente
|
| 75 |
+
if (-not $token) {
|
| 76 |
+
|
| 77 |
+
Write-Host ""
|
| 78 |
+
Write-Host "No se encontró un token guardado." -ForegroundColor Yellow
|
| 79 |
+
Write-Host "Ejecuta: hf auth login" -ForegroundColor Yellow
|
| 80 |
+
Write-Host ""
|
| 81 |
+
|
| 82 |
+
$token = Read-Host "Introduce tu token de Hugging Face"
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
if (-not $token) {
|
| 86 |
+
throw "No se proporcionó ningún token."
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
$pythonCode = @"
|
| 91 |
+
import os
|
| 92 |
+
import sys
|
| 93 |
+
from pathlib import Path
|
| 94 |
+
|
| 95 |
+
from huggingface_hub import HfApi
|
| 96 |
+
from huggingface_hub.errors import HfHubHTTPError
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
repo_id = os.environ['REPO_ID']
|
| 100 |
+
private = os.environ.get('PRIVATE', '0') == '1'
|
| 101 |
+
|
| 102 |
+
files = [
|
| 103 |
+
Path('artifacts/checkpoints/marslm-final.pt'),
|
| 104 |
+
Path('artifacts/checkpoints/config.json'),
|
| 105 |
+
Path('artifacts/tokenizer/marslm.json'),
|
| 106 |
+
]
|
| 107 |
+
|
| 108 |
+
token = os.environ.get('HF_TOKEN')
|
| 109 |
+
|
| 110 |
+
if not token:
|
| 111 |
+
raise RuntimeError('No hay token HF disponible')
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
api = HfApi(token=token)
|
| 115 |
+
|
| 116 |
+
try:
|
| 117 |
+
|
| 118 |
+
print("Creando repositorio...")
|
| 119 |
+
|
| 120 |
+
api.create_repo(
|
| 121 |
+
repo_id=repo_id,
|
| 122 |
+
exist_ok=True,
|
| 123 |
+
private=private,
|
| 124 |
+
repo_type="model"
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
for path in files:
|
| 129 |
+
|
| 130 |
+
print(f"Subiendo {path}")
|
| 131 |
+
|
| 132 |
+
api.upload_file(
|
| 133 |
+
path_or_fileobj=str(path),
|
| 134 |
+
path_in_repo=path.as_posix().split('artifacts/',1)[1],
|
| 135 |
+
repo_id=repo_id,
|
| 136 |
+
repo_type="model",
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
except HfHubHTTPError as exc:
|
| 141 |
+
|
| 142 |
+
print(
|
| 143 |
+
f"UPLOAD_FAILED: {exc}",
|
| 144 |
+
file=sys.stderr
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
raise
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
print("Upload completed")
|
| 151 |
+
|
| 152 |
+
"@
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
$tempScript = Join-Path $env:TEMP "publish_marslm.py"
|
| 156 |
+
|
| 157 |
+
Set-Content `
|
| 158 |
+
-Path $tempScript `
|
| 159 |
+
-Value $pythonCode `
|
| 160 |
+
-Encoding UTF8
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
$env:REPO_ID = $RepoId
|
| 164 |
+
$env:PRIVATE = if ($Private) { "1" } else { "0" }
|
| 165 |
+
$env:HF_TOKEN = $token
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
python $tempScript
|
| 169 |
+
|
| 170 |
+
$exitCode = $LASTEXITCODE
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
Remove-Item $tempScript -Force -ErrorAction SilentlyContinue
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
if ($exitCode -ne 0) {
|
| 177 |
+
|
| 178 |
+
throw "La publicación falló en Hugging Face Hub."
|
| 179 |
+
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
Write-Host ""
|
| 184 |
+
|
| 185 |
+
Write-Host "========================================" -ForegroundColor Green
|
| 186 |
+
Write-Host "Modelo publicado correctamente." -ForegroundColor Green
|
| 187 |
+
Write-Host "========================================" -ForegroundColor Green
|
| 188 |
+
|
| 189 |
+
Write-Host ""
|
| 190 |
+
Write-Host "Repositorio:"
|
| 191 |
+
Write-Host "https://huggingface.co/$RepoId"
|
scripts/README.md
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Antes de ejecutar cada script usa antes este comando en powersell: powershell -ExecutionPolicy Bypass -File .\\"El Script".ps1
|
| 2 |
+
|
scripts/TrainAndLearn.ps1
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
param(
|
| 2 |
+
[string]$Output = "datasets/wikipedia/programacion.txt",
|
| 3 |
+
[string]$Config = "configs/marslm-300M.yaml",
|
| 4 |
+
[string]$TokenizerPrefix = "artifacts/tokenizer/marslm",
|
| 5 |
+
[string]$VocabSize = "20000",
|
| 6 |
+
[string]$BlockSize = "512",
|
| 7 |
+
[string]$OutputDir = "artifacts/checkpoints",
|
| 8 |
+
[int]$Epochs = 10
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
$ErrorActionPreference = "Stop"
|
| 12 |
+
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
|
| 13 |
+
$repoRoot = Resolve-Path (Join-Path $scriptPath "..")
|
| 14 |
+
Set-Location $repoRoot
|
| 15 |
+
|
| 16 |
+
Write-Host "========================================" -ForegroundColor Cyan
|
| 17 |
+
Write-Host "MarsLM - Guía rápida para enseñar la IA" -ForegroundColor Cyan
|
| 18 |
+
Write-Host "========================================" -ForegroundColor Cyan
|
| 19 |
+
Write-Host ""
|
| 20 |
+
Write-Host "Paso 1/4: Preparando el corpus de entrenamiento..." -ForegroundColor Yellow
|
| 21 |
+
python -c "from pathlib import Path; src=Path('datasets/spanish_corpus_large.txt').read_text(encoding='utf-8'); Path('datasets/spanish_corpus_train.txt').write_text((src+'\n\n')*20, encoding='utf-8'); print('Corpus preparado')"
|
| 22 |
+
python datasets/download_dataset.py --output $Output --random-pages 6
|
| 23 |
+
|
| 24 |
+
Write-Host ""
|
| 25 |
+
Write-Host "Paso 2/4: Entrenando el tokenizador..." -ForegroundColor Yellow
|
| 26 |
+
python tokenizer/train_tokenizer.py --input datasets/spanish_corpus_train.txt $Output --model-prefix $TokenizerPrefix --vocab-size $VocabSize
|
| 27 |
+
|
| 28 |
+
Write-Host ""
|
| 29 |
+
Write-Host "Paso 3/4: Preprocesando los datos..." -ForegroundColor Yellow
|
| 30 |
+
python datasets/preprocess.py --input datasets/spanish_corpus_train.txt $Output --tokenizer artifacts/tokenizer/marslm.json --output artifacts/data/tokens.pt --block-size $BlockSize
|
| 31 |
+
|
| 32 |
+
Write-Host ""
|
| 33 |
+
Write-Host "Paso 4/4: Entrenando el modelo..." -ForegroundColor Yellow
|
| 34 |
+
python training/train.py --config $Config --train-file artifacts/data/tokens.pt --tokenizer-model artifacts/tokenizer/marslm.json --output-dir $OutputDir --epochs $Epochs --batch-size 1 --gradient-accumulation-steps 4 --warmup-steps 50
|
| 35 |
+
|
| 36 |
+
Write-Host ""
|
| 37 |
+
Write-Host "Proceso completado." -ForegroundColor Green
|
| 38 |
+
Write-Host "Puedes revisar los checkpoints en: $OutputDir" -ForegroundColor Green
|
scripts/TrainEvaluate.ps1
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
param(
|
| 2 |
+
[int]$Epochs = 10,
|
| 3 |
+
[string]$Config = "configs/marslm-300M.yaml",
|
| 4 |
+
[string]$Output = "datasets/wikipedia/programacion.txt"
|
| 5 |
+
)
|
| 6 |
+
|
| 7 |
+
$ErrorActionPreference = "Stop"
|
| 8 |
+
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
|
| 9 |
+
$repoRoot = Resolve-Path (Join-Path $scriptPath "..")
|
| 10 |
+
Set-Location $repoRoot
|
| 11 |
+
|
| 12 |
+
Write-Host "========================================" -ForegroundColor Cyan
|
| 13 |
+
Write-Host "MarsLM - Entrenamiento y evaluación" -ForegroundColor Cyan
|
| 14 |
+
Write-Host "========================================" -ForegroundColor Cyan
|
| 15 |
+
Write-Host ""
|
| 16 |
+
|
| 17 |
+
Write-Host "[1/4] Preparando corpus..." -ForegroundColor Yellow
|
| 18 |
+
python -c "from pathlib import Path; src=Path('datasets/spanish_corpus_large.txt').read_text(encoding='utf-8'); Path('datasets/spanish_corpus_train.txt').write_text((src+'\n\n')*20, encoding='utf-8'); print('Corpus preparado')"
|
| 19 |
+
python datasets/download_dataset.py --output $Output --random-pages 6
|
| 20 |
+
|
| 21 |
+
Write-Host ""
|
| 22 |
+
Write-Host "[2/4] Entrenando tokenizador..." -ForegroundColor Yellow
|
| 23 |
+
python tokenizer/train_tokenizer.py --input datasets/spanish_corpus_train.txt $Output --model-prefix artifacts/tokenizer/marslm --vocab-size 20000
|
| 24 |
+
|
| 25 |
+
Write-Host ""
|
| 26 |
+
Write-Host "[3/4] Preprocesando datos..." -ForegroundColor Yellow
|
| 27 |
+
python datasets/preprocess.py --input datasets/spanish_corpus_train.txt $Output --tokenizer artifacts/tokenizer/marslm.json --output artifacts/data/tokens.pt --block-size 512
|
| 28 |
+
|
| 29 |
+
Write-Host ""
|
| 30 |
+
Write-Host "[4/4] Entrenando modelo..." -ForegroundColor Yellow
|
| 31 |
+
python training/train.py --config $Config --train-file artifacts/data/tokens.pt --tokenizer-model artifacts/tokenizer/marslm.json --output-dir artifacts/checkpoints --epochs $Epochs --batch-size 1 --gradient-accumulation-steps 4 --warmup-steps 50
|
| 32 |
+
|
| 33 |
+
Write-Host ""
|
| 34 |
+
Write-Host "Entrenamiento completado." -ForegroundColor Green
|
| 35 |
+
Write-Host "Puedes probar el modelo con:" -ForegroundColor Green
|
| 36 |
+
Write-Host " powershell -ExecutionPolicy Bypass -File .\scripts\GenerateText.ps1 -Prompt 'La programación' -MaxNewTokens 60 -Temperature 0.2" -ForegroundColor Green
|
scripts/infer_model.ps1
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# PowerShell script para generar texto con el modelo MarsLM.
|
| 2 |
+
# Ejecuta este script desde el directorio MarsLM.
|
| 3 |
+
|
| 4 |
+
$root = Split-Path -Parent $MyInvocation.MyCommand.Path
|
| 5 |
+
Set-Location "$root\.."
|
| 6 |
+
|
| 7 |
+
param(
|
| 8 |
+
[string]$Prompt = "Hola, ¿puedes escribir un texto interesante?",
|
| 9 |
+
[int]$MaxNewTokens = 80
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
Write-Host "Generando texto con el checkpoint final..."
|
| 13 |
+
python inference/generate.py --model-path artifacts\checkpoints\marslm-final.pt --config artifacts\checkpoints\config.json --tokenizer-model artifacts\tokenizer\marslm.json --prompt "$Prompt" --max-new-tokens $MaxNewTokens
|
scripts/install.sh
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
pip install -r requirements.txt
|
scripts/train_model.ps1
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# PowerShell script para entrenar el modelo MarsLM desde cero.
|
| 2 |
+
# Ejecuta este script desde el directorio MarsLM.
|
| 3 |
+
|
| 4 |
+
$root = Split-Path -Parent $MyInvocation.MyCommand.Path
|
| 5 |
+
Set-Location "$root\.."
|
| 6 |
+
|
| 7 |
+
Write-Host "Instalando dependencias..."
|
| 8 |
+
python -m pip install -r requirements.txt
|
| 9 |
+
|
| 10 |
+
Write-Host "Creando carpetas de artefactos..."
|
| 11 |
+
New-Item -ItemType Directory -Path artifacts\tokenizer, artifacts\data, artifacts\checkpoints -Force | Out-Null
|
| 12 |
+
|
| 13 |
+
Write-Host "Descargando un corpus de prueba..."
|
| 14 |
+
python datasets/download_dataset.py --output datasets\tiny.txt
|
| 15 |
+
|
| 16 |
+
Write-Host "Entrenando el tokenizador..."
|
| 17 |
+
python tokenizer/train_tokenizer.py --input datasets\tiny.txt --model-prefix artifacts\tokenizer\marslm --vocab-size 20000
|
| 18 |
+
|
| 19 |
+
Write-Host "Preprocesando el corpus..."
|
| 20 |
+
python datasets/preprocess.py --input datasets\tiny.txt --tokenizer artifacts\tokenizer\marslm.json --output artifacts\data\tokens.pt --block-size 512
|
| 21 |
+
|
| 22 |
+
Write-Host "Entrenando el modelo..."
|
| 23 |
+
python training/train.py --config configs\marslm-300M.yaml --train-file artifacts\data\tokens.pt --tokenizer-model artifacts\tokenizer\marslm.json --output-dir artifacts\checkpoints --epochs 3 --batch-size 1 --gradient-accumulation-steps 4 --warmup-steps 50 --checkpoint-interval 100
|
| 24 |
+
|
| 25 |
+
Write-Host "Entrenamiento completado. Revisa artifacts\checkpoints para los checkpoints y el modelo final."
|