Skip to content

FastTree does not work in UWP #2444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
eerhardt opened this issue Feb 6, 2019 · 6 comments · Fixed by #6359
Closed

FastTree does not work in UWP #2444

eerhardt opened this issue Feb 6, 2019 · 6 comments · Fixed by #6359
Labels
enhancement New feature or request P2 Priority of the issue for triage purpose: Needs to be fixed at some point. UWP Bugs related UWP

Comments

@eerhardt
Copy link
Member

eerhardt commented Feb 6, 2019

System information

  • OS version/distro: Windows UWP app
  • .NET Version (eg., dotnet --info): UWP

Issue

FastTree is currently always attempting to PrintMemoryStats during training. This is an issue on some platforms (specifically UWP) because these APIs throw exceptions.

We should at least have a way to disable these stats when on platforms that don't support it.

  • What did you do?

Try to train a FastTree model in a UWP app.

  • What happened?

A PlatformNotSupportedException was thrown from the following method:

protected virtual void PrintMemoryStats(IChannel ch)
{
Contracts.AssertValue(ch);
ch.Trace("Training {0}", GetDatasetStatistics(TrainSet));
if (ValidSet != null)
ch.Trace("Validation {0}", GetDatasetStatistics(ValidSet));
if (TestSets != null)
{
for (int i = 0; i < TestSets.Length; ++i)
ch.Trace("ComputeTests[{1}] {0}",
GetDatasetStatistics(TestSets[i]), i);
}
if (AllowGC)
ch.Trace("GC Total Memory = {0} MB", GC.GetTotalMemory(true) / 1024 / 1024);
Process currentProcess = Process.GetCurrentProcess();
ch.Trace("Working Set = {0} MB", currentProcess.WorkingSet64 / 1024 / 1024);
ch.Trace("Virtual Memory = {0} MB",
currentProcess.VirtualMemorySize64 / 1024 / 1024);
ch.Trace("Private Memory = {0} MB",
currentProcess.PrivateMemorySize64 / 1024 / 1024);
ch.Trace("Peak Working Set = {0} MB", currentProcess.PeakWorkingSet64 / 1024 / 1024);
ch.Trace("Peak Virtual Memory = {0} MB",
currentProcess.PeakVirtualMemorySize64 / 1024 / 1024);
}

  • What did you expect?

I expected FastTree to work inside a UWP app.

Source code / logs

On UWP apps, you can't get certain information about local processes - it throws an exception:

System.PlatformNotSupportedException: Retrieving information about local processes is not supported on this platform.
   at System.Diagnostics.NtProcessInfoHelper.GetProcessInfos(Predicate`1 processIdFilter)
   at System.Diagnostics.ProcessManager.GetProcessInfo(Int32 processId, String machineName)
   at System.Diagnostics.Process.EnsureState(State state)
   at System.Diagnostics.Process.get_WorkingSet64()
@Ivanidzo4ka Ivanidzo4ka added the UWP Bugs related UWP label Feb 21, 2019
@danmoseley
Copy link
Member

I believe all of these will throw PlatformNotSupportedException so one option is just to try/catch for that.

            ch.Trace("Working Set = {0} MB", currentProcess.WorkingSet64 / 1024 / 1024);
            ch.Trace("Virtual Memory = {0} MB",
                currentProcess.VirtualMemorySize64 / 1024 / 1024);
            ch.Trace("Private Memory = {0} MB",
                currentProcess.PrivateMemorySize64 / 1024 / 1024);
            ch.Trace("Peak Working Set = {0} MB", currentProcess.PeakWorkingSet64 / 1024 / 1024);
            ch.Trace("Peak Virtual Memory = {0} MB",
                currentProcess.PeakVirtualMemorySize64 / 1024 / 1024);

Incidentally I also see use of Process.Start to launch a URL (?) in FastTree

System.Diagnostics.Process.Start(uri.AbsoluteUri + "content/GamViz/");

If that's URL I'm surprised if it works on .NET Core. In .NET Core, the default value of UseShellExecute is false. That must be true to launch the browser implicitly from a URL. If indeed that's a problem, you should explicitly set UseShellExecute to true for this launch.

Further note that on UWP, if the value is true, it will throw another PlatformNotSupportedException because it doesn't support UseShellExecute=true. You could catch that, potentially.

@danmoseley
Copy link
Member

@eerhardt tells me the Process.Start is not an issue:

The Process.Start call appears to be on an internal-only “visualization” command that is only accessible through the ML.NET command line (which isn’t shipping in v1). It is not reachable from public API, so it shouldn’t be a problem.

  • Note: it also depends on being able to start up a web server on the local machine. ☹ Good thing this code is internal.

@Jenscaasen
Copy link

Any update on this, or even an ETA?

@ganik ganik added enhancement New feature or request P2 Priority of the issue for triage purpose: Needs to be fixed at some point. labels Jan 10, 2020
@FranklinWhale
Copy link
Contributor

I think this issue affects FastTree training on WebAssembly too.

@FranklinWhale
Copy link
Contributor

blazor.webassembly.js:1 
  crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: System.Diagnostics.Process is not supported on this platform.
System.PlatformNotSupportedException: System.Diagnostics.Process is not supported on this platform.
   at System.Diagnostics.Process.GetCurrentProcess()
   at Microsoft.ML.Trainers.FastTree.FastTreeTrainerBase`3[[Microsoft.ML.Trainers.FastTree.FastForestBinaryTrainer.Options, Microsoft.ML.FastTree, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51],[Microsoft.ML.Data.BinaryPredictionTransformer`1[[Microsoft.ML.Trainers.FastTree.FastForestBinaryModelParameters, Microsoft.ML.FastTree, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]], Microsoft.ML.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51],[Microsoft.ML.Trainers.FastTree.FastForestBinaryModelParameters, Microsoft.ML.FastTree, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]].PrintMemoryStats(IChannel ch)
   at Microsoft.ML.Trainers.FastTree.FastTreeTrainerBase`3[[Microsoft.ML.Trainers.FastTree.FastForestBinaryTrainer.Options, Microsoft.ML.FastTree, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51],[Microsoft.ML.Data.BinaryPredictionTransformer`1[[Microsoft.ML.Trainers.FastTree.FastForestBinaryModelParameters, Microsoft.ML.FastTree, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]], Microsoft.ML.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51],[Microsoft.ML.Trainers.FastTree.FastForestBinaryModelParameters, Microsoft.ML.FastTree, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]].TrainCore(IChannel ch)
   at Microsoft.ML.Trainers.FastTree.FastForestBinaryTrainer.TrainModelCore(TrainContext context)
   at Microsoft.ML.Trainers.TrainerEstimatorBase`2[[Microsoft.ML.Data.BinaryPredictionTransformer`1[[Microsoft.ML.Trainers.FastTree.FastForestBinaryModelParameters, Microsoft.ML.FastTree, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]], Microsoft.ML.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51],[Microsoft.ML.Trainers.FastTree.FastForestBinaryModelParameters, Microsoft.ML.FastTree, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]].TrainTransformer(IDataView trainSet, IDataView validationSet, IPredictor initPredictor)
   at Microsoft.ML.Trainers.TrainerEstimatorBase`2[[Microsoft.ML.Data.BinaryPredictionTransformer`1[[Microsoft.ML.Trainers.FastTree.FastForestBinaryModelParameters, Microsoft.ML.FastTree, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]], Microsoft.ML.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51],[Microsoft.ML.Trainers.FastTree.FastForestBinaryModelParameters, Microsoft.ML.FastTree, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]].Fit(IDataView input)
   at BlazorWasmMl.Pages.Index.onLoad() in D:\Documents\GitHub\BlazorWasmMl\Pages\Index.razor:line 40
   at BlazorWasmMl.Pages.Index.OnInitializedAsync() in D:\Documents\GitHub\BlazorWasmMl\Pages\Index.razor:line 153
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()

@FranklinWhale
Copy link
Contributor

FastTree training on WebAssembly now works on ML.NET daily build with new FastTreeBinaryTrainer.Options { MemoryStatistics = false }. However, as multithreading is utilized during training, multithreading support on WebAssembly is required, which is only available since .NET 7 RC2.

@ghost ghost locked as resolved and limited conversation to collaborators Nov 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request P2 Priority of the issue for triage purpose: Needs to be fixed at some point. UWP Bugs related UWP
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants