|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
|
|
function Get-CommandPath($command) {
|
|
return (Get-Command $command -ErrorAction SilentlyContinue).Source
|
|
}
|
|
|
|
|
|
Write-Host "βΆ Checking for required tools (python, pip)..."
|
|
|
|
$pythonCmdPath = Get-CommandPath "python"
|
|
if ([string]::IsNullOrWhiteSpace($pythonCmdPath)) {
|
|
Write-Host "β Error: Python is not installed or not in your PATH. Please install Python 3 and try again." -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
$pipCmdPath = Get-CommandPath "pip"
|
|
if ([string]::IsNullOrWhiteSpace($pipCmdPath)) {
|
|
Write-Host "β Error: pip is not installed or not in your PATH. Please install pip and try again." -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "β
All tools are available." -ForegroundColor Green
|
|
|
|
|
|
Write-Host "`nβΆ Installing Hugging Face libraries (transformers, torch, accelerate)..."
|
|
|
|
& $pipCmdPath install transformers torch accelerate --quiet
|
|
Write-Host "β
Libraries installed successfully." -ForegroundColor Green
|
|
|
|
|
|
Write-Host "`nβΆ Locating transformers installation..."
|
|
|
|
|
|
$pipShowOutput = & $pipCmdPath show transformers
|
|
$locationLine = $pipShowOutput | Where-Object { $_ -match '^Location:' }
|
|
$sitePackagesPath = ($locationLine -split ': ', 2)[1].Trim()
|
|
|
|
if ([string]::IsNullOrWhiteSpace($sitePackagesPath)) {
|
|
Write-Host "β Error: Could not determine transformers library location via 'pip show'." -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
|
|
$transformersPath = Join-Path -Path $sitePackagesPath -ChildPath "transformers"
|
|
|
|
if (-not (Test-Path -Path $transformersPath -PathType Container)) {
|
|
Write-Host "β Error: The transformers directory was not found at the expected path: $transformersPath" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "β
Found transformers at: $transformersPath" -ForegroundColor Green
|
|
|
|
|
|
$modelPath = Join-Path -Path $transformersPath -ChildPath "models\echo"
|
|
|
|
|
|
if (Test-Path -Path $modelPath -PathType Container) {
|
|
Write-Host "β
Patch directory '$modelPath' already exists. No action needed." -ForegroundColor Yellow
|
|
Write-Host "`nπ Patching complete! You can now use 'Echo' models." -ForegroundColor Cyan
|
|
exit 0
|
|
}
|
|
|
|
Write-Host "`nβΆ Applying patch: Creating 'echo' model directory..."
|
|
|
|
New-Item -Path $modelPath -ItemType Directory -Force | Out-Null
|
|
Write-Host "β
Directory created." -ForegroundColor Green
|
|
|
|
Write-Host "βΆ Downloading model architecture files..."
|
|
$configUrl = "https://huggingface.co/MythWorxAI/Echo-mini/raw/main/configuration_echo.py"
|
|
$modelingUrl = "https://huggingface.co/MythWorxAI/Echo-mini/raw/main/modeling_echo.py"
|
|
|
|
$configOutFile = Join-Path -Path $modelPath -ChildPath "configuration_echo.py"
|
|
$modelingOutFile = Join-Path -Path $modelPath -ChildPath "modeling_echo.py"
|
|
|
|
|
|
$userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36"
|
|
|
|
|
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
|
|
|
try {
|
|
Write-Host "Downloading from: $configUrl"
|
|
Invoke-WebRequest -Uri $configUrl -OutFile $configOutFile -UserAgent $userAgent -UseBasicParsing
|
|
|
|
Write-Host "Downloading from: $modelingUrl"
|
|
Invoke-WebRequest -Uri $modelingUrl -OutFile $modelingOutFile -UserAgent $userAgent -UseBasicParsing
|
|
|
|
Write-Host "β
Model files downloaded." -ForegroundColor Green
|
|
}
|
|
catch {
|
|
|
|
$errorMessage = "β Error downloading files. "
|
|
if ($_.Exception.Response) {
|
|
$statusCode = [int]$_.Exception.Response.StatusCode
|
|
$errorMessage += "Status Code: $statusCode. "
|
|
$statusDescription = $_.Exception.Response.StatusDescription
|
|
$errorMessage += "Description: $statusDescription."
|
|
} else {
|
|
$errorMessage += "Details: $($_.Exception.Message)"
|
|
}
|
|
Write-Host $errorMessage -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "βΆ Finalizing module structure..."
|
|
|
|
$initFile = Join-Path -Path $modelPath -ChildPath "__init__.py"
|
|
New-Item -Path $initFile -ItemType File -Force | Out-Null
|
|
Write-Host "β
Module created." -ForegroundColor Green
|
|
|
|
|
|
Write-Host "`nπ Patching complete! The 'transformers' library now natively supports 'echo' models." -ForegroundColor Cyan
|
|
Write-Host " You can now load 'MythWorxAI/Echo-mini' without 'trust_remote_code=True'."
|
|
|
|
|
|
Write-Host "`nπ§ͺ To test the installation, run the following Python code:" -ForegroundColor Yellow
|
|
Write-Host @"
|
|
|
|
from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
|
|
model_id = 'MythWorxAI/Echo-mini'
|
|
print(f"Loading model: {model_id}")
|
|
|
|
# This now works without trust_remote_code=True
|
|
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
|
model = AutoModelForCausalLM.from_pretrained(model_id)
|
|
|
|
print('β
Model and tokenizer loaded successfully!')
|
|
print(model.config)
|
|
"@
|
|
|