@ -31,128 +31,132 @@ public class VladAutomatic : BaseGitPackage
new ( "https://github.com/vladmandic/automatic/raw/master/html/black-orange.jpg" ) ;
new ( "https://github.com/vladmandic/automatic/raw/master/html/black-orange.jpg" ) ;
public override bool ShouldIgnoreReleases = > true ;
public override bool ShouldIgnoreReleases = > true ;
public override SharedFolderMethod RecommendedSharedFolderMethod = >
public override SharedFolderMethod RecommendedSharedFolderMethod = > SharedFolderMethod . Symlink ;
SharedFolderMethod . Symlink ;
public override IEnumerable < TorchVersion > AvailableTorchVersions = > new [ ]
public override IEnumerable < TorchVersion > AvailableTorchVersions = >
{
new [ ] { TorchVersion . Cpu , TorchVersion . Rocm , TorchVersion . DirectMl , TorchVersion . Cuda } ;
TorchVersion . Cpu ,
TorchVersion . Rocm ,
TorchVersion . DirectMl ,
TorchVersion . Cuda
} ;
public VladAutomatic ( IGithubApiCache githubApi , ISettingsManager settingsManager , IDownloadService downloadService ,
IPrerequisiteHelper prerequisiteHelper ) :
base ( githubApi , settingsManager , downloadService , prerequisiteHelper )
{
}
// https://github.com/vladmandic/automatic/blob/master/modules/shared.py#L324
public VladAutomatic (
public override Dictionary < SharedFolderType , IReadOnlyList < string > > SharedFolders = > new ( )
IGithubApiCache githubApi ,
{
ISettingsManager settingsManager ,
[SharedFolderType.StableDiffusion] = new [ ] { "models/Stable-diffusion" } ,
IDownloadService downloadService ,
[SharedFolderType.Diffusers] = new [ ] { "models/Diffusers" } ,
IPrerequisiteHelper prerequisiteHelper
[SharedFolderType.VAE] = new [ ] { "models/VAE" } ,
)
[SharedFolderType.TextualInversion] = new [ ] { "models/embeddings" } ,
: base ( githubApi , settingsManager , downloadService , prerequisiteHelper ) { }
[SharedFolderType.Hypernetwork] = new [ ] { "models/hypernetworks" } ,
[SharedFolderType.Codeformer] = new [ ] { "models/Codeformer" } ,
[SharedFolderType.GFPGAN] = new [ ] { "models/GFPGAN" } ,
[SharedFolderType.BSRGAN] = new [ ] { "models/BSRGAN" } ,
[SharedFolderType.ESRGAN] = new [ ] { "models/ESRGAN" } ,
[SharedFolderType.RealESRGAN] = new [ ] { "models/RealESRGAN" } ,
[SharedFolderType.ScuNET] = new [ ] { "models/ScuNET" } ,
[SharedFolderType.SwinIR] = new [ ] { "models/SwinIR" } ,
[SharedFolderType.LDSR] = new [ ] { "models/LDSR" } ,
[SharedFolderType.CLIP] = new [ ] { "models/CLIP" } ,
[SharedFolderType.Lora] = new [ ] { "models/Lora" } ,
[SharedFolderType.LyCORIS] = new [ ] { "models/LyCORIS" } ,
[SharedFolderType.ControlNet] = new [ ] { "models/ControlNet" }
} ;
[SuppressMessage("ReSharper", "ArrangeObjectCreationWhenTypeNotEvident")]
// https://github.com/vladmandic/automatic/blob/master/modules/shared.py#L324
public override List < LaunchOptionDefinition > LaunchOptions = > new ( )
public override Dictionary < SharedFolderType , IReadOnlyList < string > > SharedFolders = >
{
new ( )
{
Name = "Host" ,
Type = LaunchOptionType . String ,
DefaultValue = "localhost" ,
Options = new ( ) { "--server-name" }
} ,
new ( )
new ( )
{
{
Name = "Port" ,
[SharedFolderType.StableDiffusion] = new [ ] { "models/Stable-diffusion" } ,
Type = LaunchOptionType . String ,
[SharedFolderType.Diffusers] = new [ ] { "models/Diffusers" } ,
DefaultValue = "7860" ,
[SharedFolderType.VAE] = new [ ] { "models/VAE" } ,
Options = new ( ) { "--port" }
[SharedFolderType.TextualInversion] = new [ ] { "models/embeddings" } ,
} ,
[SharedFolderType.Hypernetwork] = new [ ] { "models/hypernetworks" } ,
[SharedFolderType.Codeformer] = new [ ] { "models/Codeformer" } ,
[SharedFolderType.GFPGAN] = new [ ] { "models/GFPGAN" } ,
[SharedFolderType.BSRGAN] = new [ ] { "models/BSRGAN" } ,
[SharedFolderType.ESRGAN] = new [ ] { "models/ESRGAN" } ,
[SharedFolderType.RealESRGAN] = new [ ] { "models/RealESRGAN" } ,
[SharedFolderType.ScuNET] = new [ ] { "models/ScuNET" } ,
[SharedFolderType.SwinIR] = new [ ] { "models/SwinIR" } ,
[SharedFolderType.LDSR] = new [ ] { "models/LDSR" } ,
[SharedFolderType.CLIP] = new [ ] { "models/CLIP" } ,
[SharedFolderType.Lora] = new [ ] { "models/Lora" } ,
[SharedFolderType.LyCORIS] = new [ ] { "models/LyCORIS" } ,
[SharedFolderType.ControlNet] = new [ ] { "models/ControlNet" }
} ;
[SuppressMessage("ReSharper", "ArrangeObjectCreationWhenTypeNotEvident")]
public override List < LaunchOptionDefinition > LaunchOptions = >
new ( )
new ( )
{
{
Name = "VRAM" ,
new ( )
Type = LaunchOptionType . Bool ,
InitialValue = HardwareHelper . IterGpuInfo ( ) . Select ( gpu = > gpu . MemoryLevel ) . Max ( ) switch
{
{
Level . Low = > "--lowvram" ,
Name = "Host" ,
Level . Medium = > "--medvram" ,
Type = LaunchOptionType . String ,
_ = > null
DefaultValue = "localhost" ,
Options = new ( ) { "--server-name" }
} ,
} ,
Options = new ( ) { "--lowvram" , "--medvram" }
new ( )
} ,
{
new ( )
Name = "Port" ,
{
Type = LaunchOptionType . String ,
Name = "Force use of Intel OneAPI XPU backend" ,
DefaultValue = "7860" ,
Type = LaunchOptionType . Bool ,
Options = new ( ) { "--port" }
Options = new ( ) { "--use-ipex" }
} ,
} ,
new ( )
new ( )
{
{
Name = "VRAM" ,
Name = "Use DirectML if no compatible GPU is detected" ,
Type = LaunchOptionType . Bool ,
Type = LaunchOptionType . Bool ,
InitialValue = HardwareHelper
InitialValue = HardwareHelper . PreferDirectML ( ) ,
. IterGpuInfo ( )
Options = new ( ) { "--use-directml" }
. Select ( gpu = > gpu . MemoryLevel )
} ,
. Max ( ) switch
new ( )
{
{
Level . Low = > "--lowvram" ,
Name = "Force use of Nvidia CUDA backend" ,
Level . Medium = > "--medvram" ,
Type = LaunchOptionType . Bool ,
_ = > null
InitialValue = HardwareHelper . HasNvidiaGpu ( ) ,
} ,
Options = new ( ) { "--use-cuda" }
Options = new ( ) { "--lowvram" , "--medvram" }
} ,
} ,
new ( )
new ( )
{
{
Name = "Force use of AMD ROCm backend" ,
Name = "Force use of Intel OneAPI XPU backend" ,
Type = LaunchOptionType . Bool ,
Type = LaunchOptionType . Bool ,
InitialValue = HardwareHelper . PreferRocm ( ) ,
Options = new ( ) { "--use-ipex" }
Options = new ( ) { "--use-rocm" }
} ,
} ,
new ( )
new ( )
{
{
Name = "Use DirectML if no compatible GPU is detected" ,
Name = "CUDA Device ID" ,
Type = LaunchOptionType . Bool ,
Type = LaunchOptionType . String ,
InitialValue = HardwareHelper . PreferDirectML ( ) ,
Options = new ( ) { "--device-id" }
Options = new ( ) { "--use-directml" }
} ,
} ,
new ( )
new ( )
{
{
Name = "API" ,
Name = "Force use of Nvidia CUDA backend" ,
Type = LaunchOptionType . Bool ,
Type = LaunchOptionType . Bool ,
Options = new ( ) { "--api" }
InitialValue = HardwareHelper . HasNvidiaGpu ( ) ,
} ,
Options = new ( ) { "--use-cuda" }
new ( )
} ,
{
new ( )
Name = "Debug Logging" ,
{
Type = LaunchOptionType . Bool ,
Name = "Force use of AMD ROCm backend" ,
Options = new ( ) { "--debug" }
Type = LaunchOptionType . Bool ,
} ,
InitialValue = HardwareHelper . PreferRocm ( ) ,
LaunchOptionDefinition . Extras
Options = new ( ) { "--use-rocm" }
} ;
} ,
new ( )
{
Name = "CUDA Device ID" ,
Type = LaunchOptionType . String ,
Options = new ( ) { "--device-id" }
} ,
new ( )
{
Name = "API" ,
Type = LaunchOptionType . Bool ,
Options = new ( ) { "--api" }
} ,
new ( )
{
Name = "Debug Logging" ,
Type = LaunchOptionType . Bool ,
Options = new ( ) { "--debug" }
} ,
LaunchOptionDefinition . Extras
} ;
public override string ExtraLaunchArguments = > "" ;
public override string ExtraLaunchArguments = > "" ;
public override Task < string > GetLatestVersion ( ) = > Task . FromResult ( "master" ) ;
public override Task < string > GetLatestVersion ( ) = > Task . FromResult ( "master" ) ;
public override async Task InstallPackage ( string installLocation , TorchVersion torchVersion ,
public override async Task InstallPackage (
IProgress < ProgressReport > ? progress = null )
string installLocation ,
TorchVersion torchVersion ,
IProgress < ProgressReport > ? progress = null
)
{
{
progress ? . Report ( new ProgressReport ( - 1f , "Installing package..." , isIndeterminate : true ) ) ;
progress ? . Report ( new ProgressReport ( - 1f , "Installing package..." , isIndeterminate : true ) ) ;
// Setup venv
// Setup venv
@ -166,11 +170,13 @@ public class VladAutomatic : BaseGitPackage
{
{
// Run initial install
// Run initial install
case TorchVersion . Cuda :
case TorchVersion . Cuda :
await venvRunner . CustomInstall ( "launch.py --use-cuda --debug --test" , OnConsoleOutput )
await venvRunner
. CustomInstall ( "launch.py --use-cuda --debug --test" , OnConsoleOutput )
. ConfigureAwait ( false ) ;
. ConfigureAwait ( false ) ;
break ;
break ;
case TorchVersion . Rocm :
case TorchVersion . Rocm :
await venvRunner . CustomInstall ( "launch.py --use-rocm --debug --test" , OnConsoleOutput )
await venvRunner
. CustomInstall ( "launch.py --use-rocm --debug --test" , OnConsoleOutput )
. ConfigureAwait ( false ) ;
. ConfigureAwait ( false ) ;
break ;
break ;
case TorchVersion . DirectMl :
case TorchVersion . DirectMl :
@ -180,7 +186,8 @@ public class VladAutomatic : BaseGitPackage
break ;
break ;
default :
default :
// CPU
// CPU
await venvRunner . CustomInstall ( "launch.py --debug --test" , OnConsoleOutput )
await venvRunner
. CustomInstall ( "launch.py --debug --test" , OnConsoleOutput )
. ConfigureAwait ( false ) ;
. ConfigureAwait ( false ) ;
break ;
break ;
}
}
@ -188,11 +195,20 @@ public class VladAutomatic : BaseGitPackage
progress ? . Report ( new ProgressReport ( 1f , isIndeterminate : false ) ) ;
progress ? . Report ( new ProgressReport ( 1f , isIndeterminate : false ) ) ;
}
}
public override async Task DownloadPackage ( string installLocation ,
public override async Task DownloadPackage (
DownloadPackageVersionOptions downloadOptions , IProgress < ProgressReport > ? progress = null )
string installLocation ,
DownloadPackageVersionOptions downloadOptions ,
IProgress < ProgressReport > ? progress = null
)
{
{
progress ? . Report ( new ProgressReport ( - 1f , message : "Downloading package..." ,
progress ? . Report (
isIndeterminate : true , type : ProgressType . Download ) ) ;
new ProgressReport (
- 1f ,
message : "Downloading package..." ,
isIndeterminate : true ,
type : ProgressType . Download
)
) ;
var installDir = new DirectoryPath ( installLocation ) ;
var installDir = new DirectoryPath ( installLocation ) ;
installDir . Create ( ) ;
installDir . Create ( ) ;
@ -200,22 +216,38 @@ public class VladAutomatic : BaseGitPackage
if ( ! string . IsNullOrWhiteSpace ( downloadOptions . CommitHash ) )
if ( ! string . IsNullOrWhiteSpace ( downloadOptions . CommitHash ) )
{
{
await PrerequisiteHelper
await PrerequisiteHelper
. RunGit ( installDir . Parent ? ? "" , "clone" , "https://github.com/vladmandic/automatic" ,
. RunGit (
installDir . Name ) . ConfigureAwait ( false ) ;
installDir . Parent ? ? "" ,
"clone" ,
"https://github.com/vladmandic/automatic" ,
installDir . Name
)
. ConfigureAwait ( false ) ;
await PrerequisiteHelper . RunGit ( installLocation , "checkout" , downloadOptions . CommitHash )
await PrerequisiteHelper
. RunGit ( installLocation , "checkout" , downloadOptions . CommitHash )
. ConfigureAwait ( false ) ;
. ConfigureAwait ( false ) ;
}
}
else if ( ! string . IsNullOrWhiteSpace ( downloadOptions . BranchName ) )
else if ( ! string . IsNullOrWhiteSpace ( downloadOptions . BranchName ) )
{
{
await PrerequisiteHelper
await PrerequisiteHelper
. RunGit ( installDir . Parent ? ? "" , "clone" , "-b" , downloadOptions . BranchName ,
. RunGit (
"https://github.com/vladmandic/automatic" , installDir . Name )
installDir . Parent ? ? "" ,
"clone" ,
"-b" ,
downloadOptions . BranchName ,
"https://github.com/vladmandic/automatic" ,
installDir . Name
)
. ConfigureAwait ( false ) ;
. ConfigureAwait ( false ) ;
}
}
}
}
public override async Task RunPackage ( string installedPackagePath , string command , string arguments )
public override async Task RunPackage (
string installedPackagePath ,
string command ,
string arguments
)
{
{
await SetupVenv ( installedPackagePath ) . ConfigureAwait ( false ) ;
await SetupVenv ( installedPackagePath ) . ConfigureAwait ( false ) ;
@ -245,35 +277,44 @@ public class VladAutomatic : BaseGitPackage
VenvRunner . RunDetached ( args . TrimEnd ( ) , HandleConsoleOutput , HandleExit ) ;
VenvRunner . RunDetached ( args . TrimEnd ( ) , HandleConsoleOutput , HandleExit ) ;
}
}
public override async Task < InstalledPackageVersion > Update ( InstalledPackage installedPackage ,
public override async Task < InstalledPackageVersion > Update (
TorchVersion torchVersion , IProgress < ProgressReport > ? progress = null ,
InstalledPackage installedPackage ,
bool includePrerelease = false )
TorchVersion torchVersion ,
IProgress < ProgressReport > ? progress = null ,
bool includePrerelease = false
)
{
{
if ( installedPackage . Version is null )
if ( installedPackage . Version is null )
{
{
throw new Exception ( "Version is null" ) ;
throw new Exception ( "Version is null" ) ;
}
}
progress ? . Report ( new ProgressReport ( - 1f , message : "Downloading package update..." ,
progress ? . Report (
isIndeterminate : true , type : ProgressType . Update ) ) ;
new ProgressReport (
- 1f ,
await PrerequisiteHelper . RunGit ( installedPackage . FullPath , "checkout" ,
message : "Downloading package update..." ,
installedPackage . Version . InstalledBranch ) . ConfigureAwait ( false ) ;
isIndeterminate : true ,
type : ProgressType . Update
)
) ;
await PrerequisiteHelper
. RunGit ( installedPackage . FullPath , "checkout" , installedPackage . Version . InstalledBranch )
. ConfigureAwait ( false ) ;
var venvRunner = new PyVenvRunner ( Path . Combine ( installedPackage . FullPath ! , "venv" ) ) ;
var venvRunner = new PyVenvRunner ( Path . Combine ( installedPackage . FullPath ! , "venv" ) ) ;
venvRunner . WorkingDirectory = installedPackage . FullPath ! ;
venvRunner . WorkingDirectory = installedPackage . FullPath ! ;
venvRunner . EnvironmentVariables = SettingsManager . Settings . EnvironmentVariables ;
venvRunner . EnvironmentVariables = SettingsManager . Settings . EnvironmentVariables ;
await venvRunner . CustomInstall ( "launch.py --upgrade --test" , OnConsoleOutput )
await venvRunner
. CustomInstall ( "launch.py --upgrade --test" , OnConsoleOutput )
. ConfigureAwait ( false ) ;
. ConfigureAwait ( false ) ;
try
try
{
{
var output =
var output = await PrerequisiteHelper
await PrerequisiteHelper
. GetGitOutput ( installedPackage . FullPath , "rev-parse" , "HEAD" )
. GetGitOutput ( installedPackage . FullPath , "rev-parse" , "HEAD" )
. ConfigureAwait ( false ) ;
. ConfigureAwait ( false ) ;
return new InstalledPackageVersion
return new InstalledPackageVersion
{
{
@ -287,9 +328,14 @@ public class VladAutomatic : BaseGitPackage
}
}
finally
finally
{
{
progress ? . Report ( new ProgressReport ( 1f , message : "Update Complete" ,
progress ? . Report (
isIndeterminate : false ,
new ProgressReport (
type : ProgressType . Update ) ) ;
1f ,
message : "Update Complete" ,
isIndeterminate : false ,
type : ProgressType . Update
)
) ;
}
}
return new InstalledPackageVersion
return new InstalledPackageVersion
@ -298,7 +344,10 @@ public class VladAutomatic : BaseGitPackage
} ;
} ;
}
}
public override Task SetupModelFolders ( DirectoryPath installDirectory , SharedFolderMethod sharedFolderMethod )
public override Task SetupModelFolders (
DirectoryPath installDirectory ,
SharedFolderMethod sharedFolderMethod
)
{
{
switch ( sharedFolderMethod )
switch ( sharedFolderMethod )
{
{
@ -335,38 +384,56 @@ public class VladAutomatic : BaseGitPackage
configRoot [ "vae_dir" ] = Path . Combine ( SettingsManager . ModelsDirectory , "VAE" ) ;
configRoot [ "vae_dir" ] = Path . Combine ( SettingsManager . ModelsDirectory , "VAE" ) ;
configRoot [ "lora_dir" ] = Path . Combine ( SettingsManager . ModelsDirectory , "Lora" ) ;
configRoot [ "lora_dir" ] = Path . Combine ( SettingsManager . ModelsDirectory , "Lora" ) ;
configRoot [ "lyco_dir" ] = Path . Combine ( SettingsManager . ModelsDirectory , "LyCORIS" ) ;
configRoot [ "lyco_dir" ] = Path . Combine ( SettingsManager . ModelsDirectory , "LyCORIS" ) ;
configRoot [ "embeddings_dir" ] = Path . Combine ( SettingsManager . ModelsDirectory , "TextualInversion" ) ;
configRoot [ "embeddings_dir" ] = Path . Combine (
configRoot [ "hypernetwork_dir" ] = Path . Combine ( SettingsManager . ModelsDirectory , "Hypernetwork" ) ;
SettingsManager . ModelsDirectory ,
configRoot [ "codeformer_models_path" ] = Path . Combine ( SettingsManager . ModelsDirectory , "Codeformer" ) ;
"TextualInversion"
) ;
configRoot [ "hypernetwork_dir" ] = Path . Combine (
SettingsManager . ModelsDirectory ,
"Hypernetwork"
) ;
configRoot [ "codeformer_models_path" ] = Path . Combine (
SettingsManager . ModelsDirectory ,
"Codeformer"
) ;
configRoot [ "gfpgan_models_path" ] = Path . Combine ( SettingsManager . ModelsDirectory , "GFPGAN" ) ;
configRoot [ "gfpgan_models_path" ] = Path . Combine ( SettingsManager . ModelsDirectory , "GFPGAN" ) ;
configRoot [ "bsrgan_models_path" ] = Path . Combine ( SettingsManager . ModelsDirectory , "BSRGAN" ) ;
configRoot [ "bsrgan_models_path" ] = Path . Combine ( SettingsManager . ModelsDirectory , "BSRGAN" ) ;
configRoot [ "esrgan_models_path" ] = Path . Combine ( SettingsManager . ModelsDirectory , "ESRGAN" ) ;
configRoot [ "esrgan_models_path" ] = Path . Combine ( SettingsManager . ModelsDirectory , "ESRGAN" ) ;
configRoot [ "realesrgan_models_path" ] = Path . Combine ( SettingsManager . ModelsDirectory , "RealESRGAN" ) ;
configRoot [ "realesrgan_models_path" ] = Path . Combine (
SettingsManager . ModelsDirectory ,
"RealESRGAN"
) ;
configRoot [ "scunet_models_path" ] = Path . Combine ( SettingsManager . ModelsDirectory , "ScuNET" ) ;
configRoot [ "scunet_models_path" ] = Path . Combine ( SettingsManager . ModelsDirectory , "ScuNET" ) ;
configRoot [ "swinir_models_path" ] = Path . Combine ( SettingsManager . ModelsDirectory , "SwinIR" ) ;
configRoot [ "swinir_models_path" ] = Path . Combine ( SettingsManager . ModelsDirectory , "SwinIR" ) ;
configRoot [ "ldsr_models_path" ] = Path . Combine ( SettingsManager . ModelsDirectory , "LDSR" ) ;
configRoot [ "ldsr_models_path" ] = Path . Combine ( SettingsManager . ModelsDirectory , "LDSR" ) ;
configRoot [ "clip_models_path" ] = Path . Combine ( SettingsManager . ModelsDirectory , "CLIP" ) ;
configRoot [ "clip_models_path" ] = Path . Combine ( SettingsManager . ModelsDirectory , "CLIP" ) ;
configRoot [ "control_net_models_path" ] = Path . Combine ( SettingsManager . ModelsDirectory , "ControlNet" ) ;
configRoot [ "control_net_models_path" ] = Path . Combine (
SettingsManager . ModelsDirectory ,
var configJsonStr = JsonSerializer . Serialize ( configRoot , new JsonSerializerOptions
"ControlNet"
{
) ;
WriteIndented = true
} ) ;
var configJsonStr = JsonSerializer . Serialize (
configRoot ,
new JsonSerializerOptions { WriteIndented = true }
) ;
File . WriteAllText ( configJsonPath , configJsonStr ) ;
File . WriteAllText ( configJsonPath , configJsonStr ) ;
return Task . CompletedTask ;
return Task . CompletedTask ;
}
}
public override Task UpdateModelFolders ( DirectoryPath installDirectory ,
public override Task UpdateModelFolders (
SharedFolderMethod sharedFolderMethod ) = >
DirectoryPath installDirectory ,
SetupModelFolders ( installDirectory , sharedFolderMethod ) ;
SharedFolderMethod sharedFolderMethod
) = > SetupModelFolders ( installDirectory , sharedFolderMethod ) ;
public override Task RemoveModelFolderLinks ( DirectoryPath installDirectory ,
public override Task RemoveModelFolderLinks (
SharedFolderMethod sharedFolderMethod ) = >
DirectoryPath installDirectory ,
SharedFolderMethod sharedFolderMethod
) = >
sharedFolderMethod switch
sharedFolderMethod switch
{
{
SharedFolderMethod . Symlink = > base . RemoveModelFolderLinks ( installDirectory ,
SharedFolderMethod . Symlink
sharedFolderMethod ) ,
= > base . RemoveModelFolderLinks ( installDirectory , sharedFolderMethod ) ,
SharedFolderMethod . None = > Task . CompletedTask ,
SharedFolderMethod . None = > Task . CompletedTask ,
_ = > Task . CompletedTask
_ = > Task . CompletedTask
} ;
} ;