Skip to content

Commit

Permalink
add trt engine settings to gui
Browse files Browse the repository at this point in the history
  • Loading branch information
the-database committed Jun 6, 2024
1 parent 4b69a1c commit ddcc27f
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 7 deletions.
99 changes: 99 additions & 0 deletions VideoJaNai/Lang/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions VideoJaNai/Lang/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,40 @@
<data name="SingleVideoUpscaleTabHeader" xml:space="preserve">
<value>Single Video Upscale</value>
</data>
<data name="TensorRtDynamicEngineLabel" xml:space="preserve">
<value>Dynamic Engine</value>
</data>
<data name="TensorRtEnginePresetsLabel" xml:space="preserve">
<value>TensorRT Engine Presets</value>
</data>
<data name="TensorRtEngineSettingsDescription" xml:space="preserve">
<value>Engine generation settings to pass to the trtexec command. Choose a preset below or edit the text to use custom settings.</value>
<comment> </comment>
</data>
<data name="TensorRtEngineSettingsLabel" xml:space="preserve">
<value>TensorRT Engine Settings</value>
</data>
<data name="TensorRtPresetsDescriptionDynamicEngine" xml:space="preserve">
<value>Generate a dynamic engine which supports resolutions up to 1920x1080. Works with Compact, SPAN, 4x ESRGAN, etc.</value>
</data>
<data name="TensorRtPresetsDescriptionStaticBf16Engine" xml:space="preserve">
<value>Generate a static engine which supports a single resolution, in bfloat16 mode. %video_resolution% refers to the resolution of the video being upscaled. Necessary for DAT models. </value>
</data>
<data name="TensorRtPresetsDescriptionStaticEngine" xml:space="preserve">
<value>Generate a static engine which supports a single resolution. %video_resolution% refers to the resolution of the video being upscaled. Necessary for models that don't support dynamic engines, such as 2x ESRGAN. </value>
</data>
<data name="TensorRtPresetsDescriptionStaticOnnx" xml:space="preserve">
<value>Generate an engine from a static ONNX model. Necessary for SwinIR models.</value>
</data>
<data name="TensorRtStaticEngineBf16Label" xml:space="preserve">
<value>Static Engine bfloat16</value>
</data>
<data name="TensorRtStaticEngineLabel" xml:space="preserve">
<value>Static Engine</value>
</data>
<data name="TensorRtStaticOnnxLabel" xml:space="preserve">
<value>Static ONNX</value>
</data>
<data name="UpscaleButtonText" xml:space="preserve">
<value>Upscale</value>
</data>
Expand Down
58 changes: 56 additions & 2 deletions VideoJaNai/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ public ConcurrentQueue<string> ConsoleQueue
public static readonly string _ffmpegHevcNvenc = "hevc_nvenc -preset p7 -profile:v main10 -b:v 50M";
public static readonly string _ffmpegLossless = "ffv1";


public static readonly string _tensorRtDynamicEngine = "--fp16 --minShapes=input:1x3x8x8 --optShapes=input:1x3x1080x1920 --maxShapes=input:1x3x1080x1920 --inputIOFormats=fp32:chw --outputIOFormats=fp32:chw --tacticSources=+CUDNN,-CUBLAS,-CUBLAS_LT --skipInference";
public static readonly string _tensorRtStaticEngine = "--fp16 --optShapes=input:%video_resolution% --inputIOFormats=fp32:chw --outputIOFormats=fp32:chw --tacticSources=+CUDNN,-CUBLAS,-CUBLAS_LT --skipInference";
public static readonly string _tensorRtStaticOnnx = "--fp16 --inputIOFormats=fp32:chw --outputIOFormats=fp32:chw --tacticSources=+CUDNN,-CUBLAS,-CUBLAS_LT --skipInference";
public static readonly string _tensorRtStaticBf16Engine = "--bf16 --optShapes=input:%video_resolution% --inputIOFormats=fp32:chw --outputIOFormats=fp32:chw --tacticSources=+CUDNN,-CUBLAS,-CUBLAS_LT --skipInference";

private bool _showConsole = false;
public bool ShowConsole
Expand Down Expand Up @@ -375,6 +378,7 @@ public void SetupAnimeJaNaiConfSlot1()
configText.AppendLine($"chain_1_rife_scene_detect_threshold={CurrentWorkflow.RifeSceneDetectThreshold}");
configText.AppendLine($"chain_1_final_resize_height={CurrentWorkflow.FinalResizeHeight}");
configText.AppendLine($"chain_1_final_resize_factor={CurrentWorkflow.FinalResizeFactor}");
configText.AppendLine($"chain_1_tensorrt_engine_settings={CurrentWorkflow.TensorRtEngineSettings}");

File.WriteAllText(confPath, configText.ToString());
}
Expand Down Expand Up @@ -866,6 +870,7 @@ public bool TensorRtSelected
set
{
this.RaiseAndSetIfChanged(ref _tensorRtSelected, value);
this.RaisePropertyChanged(nameof(ShowTensorRtEngineSettings));
}
}

Expand All @@ -877,6 +882,7 @@ public bool DirectMlSelected
set
{
this.RaiseAndSetIfChanged(ref _directMlSelected, value);
this.RaisePropertyChanged(nameof(ShowTensorRtEngineSettings));
}
}

Expand All @@ -888,6 +894,28 @@ public bool NcnnSelected
set
{
this.RaiseAndSetIfChanged(ref _ncnnSelected, value);
this.RaisePropertyChanged(nameof(ShowTensorRtEngineSettings));
}
}

public bool TensorRtEngineDynamicSelected => TensorRtEngineSettings == MainWindowViewModel._tensorRtDynamicEngine;
public bool TensorRtEngineStaticSelected => TensorRtEngineSettings == MainWindowViewModel._tensorRtStaticEngine;
public bool TensorRtEngineStaticOnnxSelected => TensorRtEngineSettings == MainWindowViewModel._tensorRtStaticOnnx;
public bool TensorRtEngineStaticBf16Selected => TensorRtEngineSettings == MainWindowViewModel._tensorRtStaticBf16Engine;


private string _tensorRtEngineSettings = MainWindowViewModel._tensorRtDynamicEngine;
[DataMember]
public string TensorRtEngineSettings
{
get => _tensorRtEngineSettings;
set
{
this.RaiseAndSetIfChanged(ref _tensorRtEngineSettings, value);
this.RaisePropertyChanged(nameof(TensorRtEngineDynamicSelected));
this.RaisePropertyChanged(nameof(TensorRtEngineStaticSelected));
this.RaisePropertyChanged(nameof(TensorRtEngineStaticOnnxSelected));
this.RaisePropertyChanged(nameof(TensorRtEngineStaticBf16Selected));
}
}

Expand Down Expand Up @@ -1027,9 +1055,15 @@ public decimal? RifeSceneDetectThreshold
public bool ShowAdvancedSettings
{
get => _showAdvancedSettings;
set => this.RaiseAndSetIfChanged(ref _showAdvancedSettings, value);
set
{
this.RaiseAndSetIfChanged(ref _showAdvancedSettings, value);
this.RaisePropertyChanged(nameof(ShowTensorRtEngineSettings));
}
}

public bool ShowTensorRtEngineSettings => ShowAdvancedSettings && TensorRtSelected;

public void AddModel()
{
UpscaleSettings.Add(new UpscaleModel());
Expand Down Expand Up @@ -1099,6 +1133,26 @@ public void SetNcnnSelected()
DirectMlSelected = false;
}

public void SetDynamicEngine()
{
TensorRtEngineSettings = MainWindowViewModel._tensorRtDynamicEngine;
}

public void SetStaticEngine()
{
TensorRtEngineSettings = MainWindowViewModel._tensorRtStaticEngine;
}

public void SetStaticOnnx()
{
TensorRtEngineSettings = MainWindowViewModel._tensorRtStaticOnnx;
}

public void SetStaticBf16Engine()
{
TensorRtEngineSettings = MainWindowViewModel._tensorRtStaticBf16Engine;
}

public void Validate()
{
var valid = true;
Expand Down
30 changes: 25 additions & 5 deletions VideoJaNai/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@
<ToggleButton IsChecked="{Binding CurrentWorkflow.FfmpegX265Selected}" Content="x265 (CPU)" Command="{Binding CurrentWorkflow.SetFfmpegX265}" />
<ToggleButton IsChecked="{Binding CurrentWorkflow.FfmpegX264Selected}" Content="x264 (CPU)" Command="{Binding CurrentWorkflow.SetFfmpegX264}" />
<ToggleButton IsChecked="{Binding CurrentWorkflow.FfmpegLosslessSelected}" Content="Lossless (CPU)" Command="{Binding CurrentWorkflow.SetFfmpegLossless}" />
<TextBlock Foreground="Gray" FontSize="12" VerticalAlignment="Center" Margin="40,0,0,0" xml:space="preserve"><Bold>NVENC HEVC</Bold>: <Run Text="{x:Static lang:Resources.FfmpegPresetsDescriptionNvencHevc}" />
<Bold><hypertext:Hyperlink Url="https://ffmpeg.org/ffmpeg-codecs.html#libx265" Text="x265 (CPU)" /></Bold>: <Run Text="{x:Static lang:Resources.FfmpegPresetsDescriptionX265}" />
<Bold><hypertext:Hyperlink Url="https://ffmpeg.org/ffmpeg-codecs.html#libx264_002c-libx264rgb" Text="x264 (CPU)" /></Bold>: <Run Text="{x:Static lang:Resources.FfmpegPresetsDescriptionX264}" />
<Bold>Lossless (CPU)</Bold>: <Run Text="{x:Static lang:Resources.FfmpegPresetsDescriptionLossless}" /></TextBlock>
<TextBlock Foreground="Gray" FontSize="12" VerticalAlignment="Center" Margin="40,0,0,0" xml:space="preserve"><Run FontWeight="Bold">NVENC HEVC</Run>: <Run Text="{x:Static lang:Resources.FfmpegPresetsDescriptionNvencHevc}" />
<hypertext:Hyperlink FontWeight="Bold" Url="https://ffmpeg.org/ffmpeg-codecs.html#libx265" Text="x265 (CPU)" />: <Run Text="{x:Static lang:Resources.FfmpegPresetsDescriptionX265}" />
<hypertext:Hyperlink FontWeight="Bold" Url="https://ffmpeg.org/ffmpeg-codecs.html#libx264_002c-libx264rgb" Text="x264 (CPU)" />: <Run Text="{x:Static lang:Resources.FfmpegPresetsDescriptionX264}" />
<Run FontWeight="Bold">Lossless (CPU)</Run>: <Run Text="{x:Static lang:Resources.FfmpegPresetsDescriptionLossless}" /></TextBlock>
</StackPanel>
</StackPanel>
</Border>
Expand Down Expand Up @@ -355,7 +355,27 @@
<TextBlock Foreground="Gray" Width="900" TextWrapping="WrapWithOverflow" FontSize="12" VerticalAlignment="Center" Margin="40,0,0,0" xml:space="preserve"><Bold>TensorRT</Bold>: <Run Text="{x:Static lang:Resources.UpscalingBackendDescriptionTensorRt}" />
<Bold>DirectML</Bold>: <Run Text="{x:Static lang:Resources.UpscalingBackendDescriptionDirectMl}" />
<Bold>NCNN</Bold>: <Run Text="{x:Static lang:Resources.UpscalingBackendDescriptionNcnn}" /></TextBlock>
</StackPanel>
</StackPanel>

<StackPanel IsVisible="{Binding CurrentWorkflow.ShowTensorRtEngineSettings}">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="10,10,0,10">
<TextBlock Margin="0,0,5,0" VerticalAlignment="Center" Text="{x:Static lang:Resources.TensorRtEngineSettingsLabel}" />
<TextBox Margin="0,0,5,0" Text="{Binding CurrentWorkflow.TensorRtEngineSettings}" IsReadOnly="False" Width="900" TextWrapping="Wrap" Height="50" />
<TextBlock Width="400" TextWrapping="WrapWithOverflow" Foreground="Gray" FontSize="12" VerticalAlignment="Center" Margin="20,0,0,0" Text="{x:Static lang:Resources.TensorRtEngineSettingsDescription}" />
</StackPanel>

<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="10,10,0,10">
<TextBlock Margin="0,0,5,0" VerticalAlignment="Center" Text="{x:Static lang:Resources.TensorRtEnginePresetsLabel}" />
<ToggleButton IsChecked="{Binding CurrentWorkflow.TensorRtEngineDynamicSelected}" Content="{x:Static lang:Resources.TensorRtDynamicEngineLabel}" Command="{Binding CurrentWorkflow.SetDynamicEngine}" />
<ToggleButton IsChecked="{Binding CurrentWorkflow.TensorRtEngineStaticSelected}" Content="{x:Static lang:Resources.TensorRtStaticEngineLabel}" Command="{Binding CurrentWorkflow.SetStaticEngine}" />
<ToggleButton IsChecked="{Binding CurrentWorkflow.TensorRtEngineStaticOnnxSelected}" Content="{x:Static lang:Resources.TensorRtStaticOnnxLabel}" Command="{Binding CurrentWorkflow.SetStaticOnnx}" />
<ToggleButton IsChecked="{Binding CurrentWorkflow.TensorRtEngineStaticBf16Selected}" Content="{x:Static lang:Resources.TensorRtStaticEngineBf16Label}" Command="{Binding CurrentWorkflow.SetStaticBf16Engine}" />
<TextBlock Width="720" TextWrapping="WrapWithOverflow" Foreground="Gray" FontSize="12" VerticalAlignment="Center" Margin="40,0,0,0" xml:space="preserve"><Run FontWeight="Bold" Text="{x:Static lang:Resources.TensorRtDynamicEngineLabel}" />: <Run Text="{x:Static lang:Resources.TensorRtPresetsDescriptionDynamicEngine}" />
<Run FontWeight="Bold" Text="{x:Static lang:Resources.TensorRtStaticEngineLabel}" />: <Run Text="{x:Static lang:Resources.TensorRtPresetsDescriptionStaticEngine}" />
<Run FontWeight="Bold" Text="{x:Static lang:Resources.TensorRtStaticOnnxLabel}" />: <Run Text="{x:Static lang:Resources.TensorRtPresetsDescriptionStaticOnnx}" />
<Run FontWeight="Bold" Text="{x:Static lang:Resources.TensorRtStaticEngineBf16Label}" />: <Run Text="{x:Static lang:Resources.TensorRtPresetsDescriptionStaticBf16Engine}" /></TextBlock>
</StackPanel>
</StackPanel>
</StackPanel>
</Border>

Expand Down

0 comments on commit ddcc27f

Please sign in to comment.