Title: Model training time increase more than 10x in some case · Issue #2412 · pythonnet/pythonnet · GitHub
Open Graph Title: Model training time increase more than 10x in some case · Issue #2412 · pythonnet/pythonnet
X Title: Model training time increase more than 10x in some case · Issue #2412 · pythonnet/pythonnet
Description: Environment Pythonnet version: 3.0.3 Python version: 3.10.14 Environment Versions PyTorch version: 2.3.0+cpu Is debug build: False Python platform: Windows-10-10.0.22631-SP0 Is CUDA available: False CUDA runtime version: 12.4.99 CUDA_MOD...
Open Graph Description: Environment Pythonnet version: 3.0.3 Python version: 3.10.14 Environment Versions PyTorch version: 2.3.0+cpu Is debug build: False Python platform: Windows-10-10.0.22631-SP0 Is CUDA available: Fals...
X Description: Environment Pythonnet version: 3.0.3 Python version: 3.10.14 Environment Versions PyTorch version: 2.3.0+cpu Is debug build: False Python platform: Windows-10-10.0.22631-SP0 Is CUDA available: Fals...
Opengraph URL: https://github.com/pythonnet/pythonnet/issues/2412
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Model training time increase more than 10x in some case","articleBody":"### Environment\r\n\r\n- Pythonnet version: 3.0.3\r\n- Python version: 3.10.14\r\n- Environment Versions\r\n PyTorch version: 2.3.0+cpu\r\n Is debug build: False\r\n Python platform: Windows-10-10.0.22631-SP0\r\n Is CUDA available: False\r\n CUDA runtime version: 12.4.99\r\n CUDA_MODULE_LOADING set to: N/A\r\n GPU models and configuration: GPU 0: NVIDIA GeForce RTX 4060 Laptop GPU\r\n Nvidia driver version: 556.12\r\n cuDNN version: C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.4\\bin\\cudnn_ops_train64_8.dll\r\n HIP runtime version: N/A\r\n MIOpen runtime version: N/A\r\n Is XNNPACK available: True\r\n \r\n Versions of relevant libraries:\r\n [pip3] numpy==1.26.4\r\n [pip3] torch==2.3.0\r\n [pip3] torchaudio==2.3.0\r\n [pip3] torchvision==0.18.0\r\n [conda] blas 1.0 mkl\r\n [conda] mkl 2021.4.0 pypi_0 pypi\r\n [conda] mkl-service 2.4.0 py310h2bbff1b_1\r\n [conda] mkl_fft 1.3.8 py310h2bbff1b_0\r\n [conda] mkl_random 1.2.4 py310h59b6b97_0\r\n [conda] numpy 1.26.4 py310h055cbcc_0\r\n [conda] numpy-base 1.26.4 py310h65a83cf_0\r\n [conda] torch 2.3.0 pypi_0 pypi\r\n [conda] torchaudio 2.3.0 pypi_0 pypi\r\n [conda] torchvision 0.18.0 pypi_0 pypi\r\n- Operating System:\r\n OS: Microsoft Windows 11 \r\n GCC version: Could not collect\r\n Clang version: Could not collect\r\n CMake version: version 3.29.0-rc3\r\n Libc version: N/A\r\n\r\n- .NET Runtime:\r\n .NET framework 4.8\r\n```python\r\nimport torch\r\npara =torch.Tensor(initial_para)\r\nx,y = torch.tensor(x),torch.relu(torch.tensor(y))\r\npara.requires_grad = True\r\nloss = torch.nn.MSELoss()\r\noptimizer = torch.optim.Adam([para], lr=lr)\r\nfor i in `range(max_iter):`\r\n y_fit = multi_gaussian(x,para)\r\n l = loss(y_fit,y)\r\n try:\r\n if torch.isnan(l) or torch.isinf(l) :\r\n print(\"l is nan or inf\")\r\n break\r\n l.backward()\r\n optimizer.step()\r\n optimizer.zero_grad()\r\n except:\r\n break\r\ndef multi_gaussian(x, params):\r\n y = torch.zeros_like(x)\r\n for i in range(0, params.shape[0], 3):\r\n g = gaussian(x, params[i], params[i + 1], params[i + 2])\r\n if torch.any(torch.isnan(g)) or torch.any(torch.isinf(g)):\r\n continue\r\n y = y + g\r\n return y\r\ndef gaussian(x,center,amp,variance, offset = None):\r\n return amp*torch.exp(-(x-center)**2/(variance ))\r\n```\r\n\r\n\r\n### Details\r\nHi, im using pytorch to fit gaussian mixture model. It works perfect via directly run main.py. My data had length of 1024, and it only took less than 0.1 s to fit the model. However, a strange issue occurred when I using PythonNet package in CSharp. After the python environment was initialized, the main.py was also successfully runned. But the time for model fit increased to nearly 1.8 s, 18 times slower than previous condition.\r\nWhile i used another fit methed named scipy.optimize.curve_fit method, it tooks almost the same time (0.03 s) as run main.py directly or by CSharp code call. I was so confused by the difference, and I want to know if there is way to solve the problem.\r\n\r\n(By the way, im coding my program in net4.8 framework, i cant using torchsharp in Csharp which need net6.0).\r\n\r\nThank a lot!\r\n","author":{"url":"https://github.com/s1030512149","@type":"Person","name":"s1030512149"},"datePublished":"2024-07-05T03:12:13.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/2412/pythonnet/issues/2412"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d9bb172b-3060-34dc-a399-bd4866146927 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DAE6:8F24B:3DD4B04:564CB35:69713274 |
| html-safe-nonce | 4f0d57c403e1938517d3e3dadb355e12bc0c19e57de7d7e22c8fe9051cf229a3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQUU2OjhGMjRCOjNERDRCMDQ6NTY0Q0IzNTo2OTcxMzI3NCIsInZpc2l0b3JfaWQiOiIzODQ5ODgzMzQ1ODcyODI2OTk2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 068d46ebf085b11781301fe96e1a906beb826d21c4cd483fb7bf9218edb77224 |
| hovercard-subject-tag | issue:2391687290 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/pythonnet/pythonnet/2412/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9683d036e42d43f03e0ad6482fd0ccbe27b8e3bec32c1d02acbaa9cbb0707b07/pythonnet/pythonnet/issues/2412 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9683d036e42d43f03e0ad6482fd0ccbe27b8e3bec32c1d02acbaa9cbb0707b07/pythonnet/pythonnet/issues/2412 |
| og:image:alt | Environment Pythonnet version: 3.0.3 Python version: 3.10.14 Environment Versions PyTorch version: 2.3.0+cpu Is debug build: False Python platform: Windows-10-10.0.22631-SP0 Is CUDA available: Fals... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | s1030512149 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0c91dba94f720b71e069760db74b45f0f69e50caa632dc4e976d5bf46c8242ee |
| turbo-cache-control | no-preview |
| go-import | github.com/pythonnet/pythonnet git https://github.com/pythonnet/pythonnet.git |
| octolytics-dimension-user_id | 6050430 |
| octolytics-dimension-user_login | pythonnet |
| octolytics-dimension-repository_id | 14748123 |
| octolytics-dimension-repository_nwo | pythonnet/pythonnet |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 14748123 |
| octolytics-dimension-repository_network_root_nwo | pythonnet/pythonnet |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e6c1902093917264567791cc30776acd1b2490c9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width