-
Notifications
You must be signed in to change notification settings - Fork 29
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
Exp run fails when launched via Experiments tab, but runs via command line #1815
Comments
@shcheklein I think we already have a ticket for this issue. Right? This is something that happened to me also and we have talked about this last week. |
Relates to #1791. A few questions:
|
Because that project needs a GPU, I am using this TPI repo https://github.com/iterative/tpi-remote-vscode to setup remote interpreter in VSCode.
|
Also, I suspect this issue may have something to do with this: |
Yep, I can recreate in a terminal if I do not use those setup steps:
|
Right. Why don't we activate the entire virtual env when running dvc via the extension? (instead of using only the interpreter) |
Thanks! |
We made a decision a long time ago not to try and recreate the logic in the Python extension which is used to "auto-activate" virtual environments.
Currently, the Python extension does not actually expose the activation details. We don't know the details of the expected activation file. |
Got it, thanks! |
For the record: I've been looking into this further. There is a "VS Code" way to set the LMK what you think. |
@alex000kim if you run a Terminal inside VS Code and do As far as I understand Looking into this
@alex000kim Can it be the case that you also have |
Nope
Yes. And this is exactly what happens when I run What @mattseddon is suggesting (i.e. using |
Another byproduct of this issue. stages:
check_packages:
cmd: pipenv run pip freeze > requirements.txt
always_changed: true
outs:
- requirements.txt
... And because the extension is running Running: dvc exp run --run-all
Running stage 'check_packages':
> pipenv run pip freeze > requirements.txt
Creating a virtualenv for this project…
Using /home/ubuntu/.virtualenvs/magnetic-tiles-defect-clR5l9w5/bin/python3 (3.8.10) to create virtualenv…
created virtual environment CPython3.8.10.final.0-64 in 117ms
creator CPython3Posix(dest=/home/ubuntu/.local/share/virtualenvs/tmpx6eibpu2-HTVzh22Z, clear=False, global=False)
seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, pkg_resources=latest, via=copy, app_data_dir=/home/ubuntu/.local/share/virtualenv/seed-app-data/v1.0.1.debian.1)
activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
Virtualenv location: /home/ubuntu/.local/share/virtualenvs/tmpx6eibpu2-HTVzh22Z
WARNING: 'requirements.txt' is empty.
Updating lock file 'dvc.lock' Other stages of the pipeline depend on |
thanks @alex000kim ! It feels I still don't understand how
how do you usually run
either I'm missing something, or it is supposed to be this way. That's why you have to wrap into |
I think one of the major differences between (
$ pipenv install # run this once to install deps from Pipfile
$ pipenv shell # spawns a new shell subprocess
(project_venv) $ dvc exp run See: https://pipenv.pypa.io/en/latest/basics/#example-pipenv-workflow |
Okay, I see a few things confused me.
For me I had to manually set |
@alex000kim removing
The only thing is that it's stuck on > python src/stages/train.py --config=params.yaml
/Users/ivan/.local/share/virtualenvs/magnetic-tiles-defect-4MZ-4MEx/lib/python3.9/site-packages/torch/_tensor.py:1142: UserWarning: __floordiv__ is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the 'trunc' function NOT 'floor'). This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode='trunc'), or for actual floor division, use torch.div(a, b, rounding_mode='floor').
ret = func(*args, **kwargs)
INFO:dvclive:Overriding _path with value provided by DVC: training_metrics
INFO:dvclive:Report path (if generated): /Users/ivan/Projects/magnetic-tiles-defect/training_metrics_dvc_plots/index.html
epoch train_loss valid_loss foreground_acc jaccard_coeff dice_multi time
[W ParallelNative.cpp:229] Warning: Cannot set number of intraop threads after parallel work has started or after set_num_threads call when using native parallel backend (function set_num_threads)
[W ParallelNative.cpp:229] Warning: Cannot set number of intraop threads after parallel work has started or after set_num_threads call when using native parallel backend (function set_num_threads)
[W ParallelNative.cpp:229] Warning: Cannot set number of intraop threads after parallel work has started or after set_num_threads call when using native parallel backend (function set_num_threads) but it looks like it's a separate issue related to the project itself. Also, a different bug is here - #1837 that should be addressed. |
Oh, good point! So this would solve this particular issue. The question of how to approach env variables from virtual envs is still open.
Yeah, I think that's something to do with pytorch running in MacOS (maybe even M1 specific) |
Hmm, either I'm missing something or it's not an issue. For me after removing |
I believe it works now because of a recent workaround I made (specifically to address this issue): iterative/magnetic-tiles-defect@8ccc5fb Before, I used to set |
Okay, but it's the same if I do it in a regular terminal (even outside VS Code):
gives me: Traceback (most recent call last):
File "/Users/ivan/Projects/magnetic-tiles-defect/src/stages/data_load.py", line 8, in <module>
from src.data_utils import dataset_prep
ModuleNotFoundError: No module named 'src' If looks to me like a general Python path problem, right? |
Yes, it's a general python problem, but if you run: echo "export PYTHONPATH=$PWD" >> $VIRTUAL_ENV/bin/activate
source $VIRTUAL_ENV/bin/activate you address the problem without having to resort to the hack of doing: import sys
sys.path.append(<dir_path>) The right We do this in several places (including teaching this as part of the online course):
|
Sounds like a hack, not sure virtualenv file made to be modified. I think I would either use relative paths in imports (I think should be possible, right?). It will be easier to use projects I think. Need to do a bit of reserach here ... But, I understand the problem finally, and ideally it should be working no matter if we use it in the demo projects or not, since VS Code terminal supports it. @mattseddon could you please point me to the code that runs DVC commands? how does it interact with MS Python extension? |
There is a fair bit of logic there. I would start in This is next on my list of things to fix. I have not tested yet but I am hoping that when quick test: Remove sys hack from project and then run
Seems to work! We should be able to update the setup wizard to ask the user which package manager they use ( |
Automatic loading of |
Wrapping up everything with |
Do I get it right, but it's not even |
From #1815 (comment)
Currently, the Python extension does not actually expose the activation details. We don't know the details of the expected activation file. For now I willHack around with the interpreter path that we are given specifically for the runner and AlternativeGo back to sending commands directly to our own integrated terminal as we did back in 2020: Screen.Recording.2021-01-22.at.10.29.04.am.movWe can reliably wait for the terminal to be activated based on this hack but moving back to the integrated terminal would bring its own set of problems we'd need to workaround. See #51 (comment). Notes:There are a lot of outstanding issues around virtual environments and package managers within the Python extension: microsoft/vscode-python#8870 All of them seem to come back to microsoft/vscode-python#11039 as the grand plan for solving everything. I have already commented on the issue and I will continue to watch to see how it develops. Pipenv specific details: |
Thanks, @mattseddon . Awesome research and summary. I think we should probably close this specific ticket and consolidate all this info in one place? There is nothing that unique to this situation. We can summarize some workarounds that work here in the description for the community. Regarding the solution - how much of an effort it would be to copy-paste the logic from MS Python - is it open source? |
Yes, it is open source. It would be a significant amount of effort. Even finding the specific part of the code is difficult. I will raise an issue to have the activation command added to their API. |
Closing this in favour of #1791. Proposal for a workaround that we can implement is here: #1791 (comment) |
@alex000kim I have found another workaround for this issue.
This should put the Hope this helps as an interim solution (better than I will keep working on it 👍🏻. |
See https://www.loom.com/share/bbefd727e9044467b56cd1891d9e4452
When I launch an experiment via the Experiments tab, it fails because of an import error.
Launching the same experiment via the command line works fine.
It looks like there's a difference in environment variables.
Is it possible that the extension is not using my virtual environment?
I am using
pipenv
to manage the virtual env in this project.The text was updated successfully, but these errors were encountered: