Closed taylover12138 closed 8 months ago
Hey @taylover12138
Thanks for using the library!
pip install pytorch-widedeep==1.4.0
Will install the previous version
However, if you give me more details on the functoning problems that the current version has I will try to fix them 🙂
I ran the example on your GitHub and it gave me this error: ![Uploading 屏幕截图 2024-03-08 145557.png…]()
Hey @taylover12138
Thanks for using the library!
pip install pytorch-widedeep==1.4.0
Will install the previous version
However, if you give me more details on the functoning problems that the current version has I will try to fix them 🙂
Now the program gets an error:
C:\Users\tgz.conda\envs\tabnet\Lib\site-packages\pytorch_widedeep\datasets_base.py:49: DeprecationWarning: path is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.
with resources.path(
C:\Users\tgz.conda\envs\tabnet\Lib\site-packages\pytorch_widedeep\preprocessing\tab_preprocessor.py:360: UserWarning: Continuous columns will not be normalised
warnings.warn("Continuous columns will not be normalised")
0%| | 0/153 [00:00<?, ?it/s]Traceback (most recent call last):
File "
I'm still using the same version: 1.5.0
When I changed to version 1.2.0, the program gave me an error:
0%| | 0/153 [00:48<?, ?it/s]
Traceback (most recent call last):
File "E:\projects\class\tabnet\src\tabdemo.py", line 81, in
@5uperpalo you have a windows machine and maybe you can help?
This is that conda/spawn mutiprocessing issue.
@taylover12138 in the meantime, do you have access to a linux machine?
@5uperpalo you have a windows machine and maybe you can help?
This is that conda/spawn mutiprocessing issue.
@taylover12138 in the meantime, do you have access to a linux machine?
I don't have Linux, I have Windows
I wanted to change 'num_workers', but I couldn't find the hyperparameter
sir,i can use it in the linux machine,but still not in windows
@taylover12138 could you please provide a code snippet(or example script from the repository) that you are trying to run? I will try to run/troubleshoot it in Win10 OS , but tbh I never run any code under Win, I always go for WSL due to torch, torch_vision, multiprocessing etc. related issues when using Windows
@taylover12138 could you please provide a code snippet(or example script from the repository) that you are trying to run? I will try to run/troubleshoot it in Win10 OS , but tbh I never run any code under Win, I always go for WSL due to torch, torch_vision, multiprocessing etc. related issues when using Windows I ran the example code you provided: import numpy as np import torch from sklearn.model_selection import train_test_split
from pytorch_widedeep import Trainer from pytorch_widedeep.preprocessing import WidePreprocessor, TabPreprocessor from pytorch_widedeep.models import Wide, TabMlp, WideDeep from pytorch_widedeep.metrics import Accuracy from pytorch_widedeep.datasets import load_adult
df = load_adult(as_frame=True) df["income_label"] = (df["income"].apply(lambda x: ">50K" in x)).astype(int) df.drop("income", axis=1, inplace=True) df_train, df_test = train_test_split(df, test_size=0.2, stratify=df.income_label)
wide_cols = [ "education", "relationship", "workclass", "occupation", "native-country", "gender", ] crossed_cols = [("education", "occupation"), ("native-country", "occupation")]
cat_embed_cols = [ "workclass", "education", "marital-status", "occupation", "relationship", "race", "gender", "capital-gain", "capital-loss", "native-country", ] continuous_cols = ["age", "hours-per-week"] target = "income_label" target = df_train[target].values
wide_preprocessor = WidePreprocessor(wide_cols=wide_cols, crossed_cols=crossed_cols) X_wide = wide_preprocessor.fit_transform(df_train)
tab_preprocessor = TabPreprocessor( cat_embed_cols=cat_embed_cols, continuous_cols=continuous_cols # type: ignore[arg-type] ) X_tab = tab_preprocessor.fit_transform(df_train)
wide = Wide(input_dim=np.unique(X_wide).shape[0], pred_dim=1) tab_mlp = TabMlp( column_idx=tab_preprocessor.column_idx, cat_embed_input=tab_preprocessor.cat_embed_input, continuous_cols=continuous_cols, ) model = WideDeep(wide=wide, deeptabular=tab_mlp)
trainer = Trainer(model, objective="binary", metrics=[Accuracy]) trainer.fit( X_wide=X_wide, X_tab=X_tab, target=target, n_epochs=5, batch_size=256, )
X_wide_te = wide_preprocessor.transform(df_test) X_tab_te = tab_preprocessor.transform(df_test) preds = trainer.predict(X_wide=X_wide_te, X_tab=X_tab_te)
trainer.save(path="model_weights", save_state_dict=True)
torch.save(model.state_dict(), "model_weights/wd_model.pt")
model_new = WideDeep(wide=wide, deeptabular=tab_mlp) model_new.load_state_dict(torch.load("model_weights/wd_model.pt"))
trainer_new = Trainer(model_new, objective="binary")
preds = trainer_new.predict(X_wide=X_wide, X_tab=X_tab)
And,My package's version is as follows: Package Version
annotated-types 0.6.0 blis 0.7.11 catalogue 2.0.10 certifi 2024.2.2 charset-normalizer 3.3.2 click 8.1.7 cloudpathlib 0.16.0 colorama 0.4.6 confection 0.1.4 cramjam 2.8.2 cymem 2.0.8 einops 0.7.0 fastparquet 2024.2.0 filelock 3.9.0 fsspec 2023.4.0 gensim 4.3.2 idna 3.6 imutils 0.5.4 Jinja2 3.1.2 joblib 1.3.2 langcodes 3.3.0 lightning-utilities 0.10.1 MarkupSafe 2.1.3 mpmath 1.3.0 murmurhash 1.0.10 networkx 3.2.1 numpy 1.26.3 opencv-contrib-python 4.9.0.80 packaging 23.2 pandas 2.2.1 pillow 10.2.0 pip 23.3.1 preshed 3.0.9 pyarrow 15.0.1 pydantic 2.6.3 pydantic_core 2.16.3 python-dateutil 2.9.0.post0 pytorch-widedeep 1.5.0 pytz 2024.1 requests 2.31.0 scikit-learn 1.4.1.post1 scipy 1.12.0 setuptools 68.2.2 six 1.16.0 smart-open 6.4.0 spacy 3.7.4 spacy-legacy 3.0.12 spacy-loggers 1.0.5 srsly 2.4.8 sympy 1.12 thinc 8.2.3 threadpoolctl 3.3.0 torch 2.2.1+cu121 torchaudio 2.2.1+cu121 torchmetrics 1.3.1 torchvision 0.17.1+cu121 tqdm 4.66.2 typer 0.9.0 typing_extensions 4.8.0 tzdata 2024.1 urllib3 2.2.1 wasabi 1.1.2 weasel 0.3.4 wheel 0.41.2 wrapt 1.16.0
@taylover12138
pip install pytorch_widedeep
under this envif __name__ == '__main__'
before the start of the code and batch_size
to the final line to avoid the error in the predictions, i.e.:
from pytorch_widedeep.datasets import load_adult
if name == 'main' df = load_adult(as_frame=True) ... preds = trainer_new.predict(X_wide=X_wide, X_tab=X_tab, batch_size=256)
* now it is working
Please confirm if this fixes your problem?
# Explanation
* follow the link in [this comment](https://stackoverflow.com/a/18205086) - "For an explanation of why (on Windows) the if __name__ == '__main__' part is necessary, see Programming guidelines."
# Note
* please for your own sake avoid multiprocessing and possibly python coding under Windows and rather use WSL and venv as opposed to Win10 + Anaconda
@5uperpalo thank you for stepping in 😉
@taylover12138
what I did
- I created "fresh" python 3.8 env in my Conda on WIndows 10; I never use python/vs code/conda under Windows so I have some 2-3years old Anaconda installation, but good enough for troubleshooting
- I did
pip install pytorch_widedeep
under this env- I ran the code from README.MD of the repo
- I received same error as you did
- I added
if __name__ == '__main__'
before the start of the code andbatch_size
to the final line to avoid the error in the predictions, i.e.:from pytorch_widedeep.datasets import load_adult if __name__ == '__main__' df = load_adult(as_frame=True) ... preds = trainer_new.predict(X_wide=X_wide, X_tab=X_tab, batch_size=256)
- now it is working
Please confirm if this fixes your problem?
Explanation
- follow the link in this comment - "For an explanation of why (on Windows) the if name == 'main' part is necessary, see Programming guidelines."
Note
- please for your own sake avoid multiprocessing and possibly python coding under Windows and rather use WSL and venv as opposed to Win10 + Anaconda
@jrzaurin and @5uperpalo Thank you so much sir !i fixed it!
How to install the previous version, the current 1.5 version has been working problems?