You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched the opened issues and there are no duplicates
Describe the bug
When using the optimizer AdamW within Pytorch, and using Flet Build macos, the application errors with:
"OSError: could not get source code"
It also occurs with NAdam as well.
Note, that Flet Build is still stripping off all bin directories (0.24.1), and these have to be manually inserted to get the code to the failure point, else it will fail due to lack of the bin directory. (see #3060 )
To manually get the bin folder working:
Take the bin folder from the development environment, location:
/.venv/lib/python3.12/site-packages/torch/bin
and copy it to:
/Users/[USER]/Library/Caches/flet_demo-1.0.0-1/app/pypackages/torch
Code sample
Code
importfletasftimporttorchimporttorch.nnasnnimporttorch.optimasoptim# Simple model (replace with your actual model)classSimpleModel(nn.Module):
def__init__(self):
super(SimpleModel, self).__init__()
self.fc=nn.Linear(10, 1) # Adjust input/output sizes as neededdefforward(self, x):
returnself.fc(x)
# Initialize model and optimizermodel=SimpleModel()
optimizer=optim.AdamW(model.parameters(), lr=0.001)
defmain(page: ft.Page):
page.title="PyTorch Model with Flet"# Sample input data input_data=torch.randn(1, 10)
deftrain_click(e):
# Sample training loop output=model(input_data)
loss=torch.mean(output) # Simple loss for illustrationoptimizer.zero_grad()
loss.backward()
optimizer.step()
page.snack_bar=ft.SnackBar(ft.Text(f"Loss: {loss.item()}"))
page.snack_bar.open=Truepage.update()
page.add(
ft.ElevatedButton("Train", on_click=train_click),
)
ft.app(target=main)
To reproduce
To reproduce this error:
Environment
Python 3.12.5 (the issue is also present in 3.11.9)
Flet 0.24.1
Pytorch 2.3.1
Command:
Flet CLI = flet build macos
Expected behavior
The application should operate correctly.
Screenshots / Videos
Captures
[Upload media here]
Operating System
macOS
Operating system details
MacOS 14.6.1
Flet version
0.24.1
Regression
No, it isn't
Suggestions
No response
Logs
Logs
The full error log is contained below:/var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function upsample at 0x1234942c0>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function upsample at 0x123494360>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function interpolate at 0x123494680>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function interpolate at 0x123494720>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function interpolate at 0x123494860>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function interpolate at 0x1234949a0>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function upsample_nearest at 0x123494c20>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function upsample_nearest at 0x123494cc0>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function upsample_bilinear at 0x123494f40>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function upsample_bilinear at 0x123494fe0>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function upsample_bilinear at 0x123495120>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function upsample_bilinear at 0x123495260>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function RNN.forward at 0x12358c5e0>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function RNN.forward at 0x12358c860>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function LSTM.forward at 0x12358cf40>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function LSTM.forward at 0x12358d120>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function GRU.forward at 0x12358d580>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function GRU.forward at 0x12358d760>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function tensordot at 0x1236405e0>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function tensordot at 0x123640680>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function tensordot at 0x1236407c0>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function tensordot at 0x123640900>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function norm at 0x123640f40>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function norm at 0x123641080>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function norm at 0x123641120>./var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_jit_internal.py:872: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function norm at 0x1236411c0>.Traceback (most recent call last): File "<string>", line 43, in <module> File "<frozen runpy>", line 229, in run_module File "<frozen runpy>", line 88, in _run_code File "/var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/main.py", line 17, in <module> File "/var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/optim/adamw.py", line 72, in __init__ File "/var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/optim/optimizer.py", line 367, in __init__ File "/var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_compile.py", line 26, in inner File "/var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_dynamo/__init__.py", line 2, in <module> File "/var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/_dynamo/convert_frame.py", line 39, in <module> File "/var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/fx/experimental/symbolic_shapes.py", line 48, in <module> File "/var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/fx/experimental/_config.py", line 76, in <module> File "/var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/utils/_config_module.py", line 58, in install_config_module File "/var/folders/gv/yy0v6h9s32d63pwl8nx1mgcw0000gn/T/serious_python_tempDgq7zi/__pypackages__/torch/utils/_config_module.py", line 75, in get_assignments_with_compile_ignored_comments File "./inspect.py", line 1262, in getsource File "./inspect.py", line 1244, in getsourcelines File "./inspect.py", line 1081, in findsourceOSError: could not get source code
Additional details
No response
The text was updated successfully, but these errors were encountered:
ap4499
changed the title
Serious_Python, import error with AdamW (Pytorch Optimizer)
Import error with AdamW (Pytorch Optimizer)
Sep 12, 2024
ap4499
changed the title
Import error with AdamW (Pytorch Optimizer)
Import error with Pytorch optimizers (AdamW)
Sep 12, 2024
Duplicate Check
Describe the bug
When using the optimizer AdamW within Pytorch, and using Flet Build macos, the application errors with:
"OSError: could not get source code"
It also occurs with NAdam as well.
Note, that Flet Build is still stripping off all bin directories (0.24.1), and these have to be manually inserted to get the code to the failure point, else it will fail due to lack of the bin directory. (see #3060 )
To manually get the bin folder working:
Take the bin folder from the development environment, location:
/.venv/lib/python3.12/site-packages/torch/bin
and copy it to:
/Users/[USER]/Library/Caches/flet_demo-1.0.0-1/app/pypackages/torch
Code sample
Code
To reproduce
To reproduce this error:
Environment
Python 3.12.5 (the issue is also present in 3.11.9)
Flet 0.24.1
Pytorch 2.3.1
Command:
Flet CLI = flet build macos
Expected behavior
The application should operate correctly.
Screenshots / Videos
Captures
[Upload media here]
Operating System
macOS
Operating system details
MacOS 14.6.1
Flet version
0.24.1
Regression
No, it isn't
Suggestions
No response
Logs
Logs
Additional details
No response
The text was updated successfully, but these errors were encountered: