Repository: jankrepl/mltype (language: python)

Issue:
Sampling / training failure
Hi there. I have an issue with the sampling and training.

Sampling steps with pretrained:
1. Downloaded .zip archive from https://github.com/raywenderlich/swift-algorithm-club
2. put it into .mltype/languages
3. run ```mlt sample swift.zip```
4. Get this 
```
Traceback (most recent call last):
  File "/usr/local/bin/mlt", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/mltype/cli.py", line 575, in sample
    network, vocabulary = load_model(model_folder)
  File "/usr/local/lib/python3.9/site-packages/mltype/ml.py", line 839, in load_model
    output_dict = torch.load(path, map_location=torch.device("cpu"))
  File "/usr/local/lib/python3.9/site-packages/torch/serialization.py", line 705, in load
    with _open_zipfile_reader(opened_file) as opened_zipfile:
  File "/usr/local/lib/python3.9/site-packages/torch/serialization.py", line 243, in __init__
    super(_open_zipfile_reader, self).__init__(torch._C.PyTorchFileReader(name_or_buffer))
RuntimeError: Expected hasRecord("version") to be true, but got false.  (Could this error message be improved?  If so, please report an enhancement request to PyTorch.)
```

Training steps:
0. having some random `*.txt` file
1. run `mlt train sometext.txt my_model`
2. get this
```
============================ Parameters | 10:17:48 =============================
{'batch_size': 64,
 'checkpoint_path': None,
 'dense_size': 128,
 'early_stopping': False,
 'extensions': None,
 'fill_strategy': 'skip',
 'gpus': None,
 'hidden_size': 32,
 'illegal_chars': None,
 'max_epochs': 10,
 'model_name': 'my_model',
 'n_layers': 1,
 'output_path': None,
 'path': ('sometext.txt',),
 'train_test_split': 0.9,
 'use_mlflow': False,
 'vocab_size': 50,
 'window_size': 50}
========================== Reading file(s) | 10:17:48 ==========================
BinarySearch.txt
======================= Computing vocabulary | 10:17:48 ========================
# characters: 50
[' ', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', ':', '<', '=', '>', '?', 'B', 'C', 'I', 'N', 'S', 'T', '[', ']', '_', 'a', 'b', 'c', 'd', 'e', 'f', 'h', 'i', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', '{', '}']
======================= Creating training set | 10:17:48 =======================
100%|████████████████████████████████████████████| 1/1 [00:00<00:00, 167.42it/s]
X.dtype=int8, y.dtype=int8
Train: 424
Validation: 48
Traceback (most recent call last):
  File "/usr/local/bin/mlt", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/mltype/cli.py", line 326, in train
    run_train(
  File "/usr/local/lib/python3.9/site-packages/mltype/ml.py", line 762, in run_train
    chp_callback = pl.callbacks.ModelCheckpoint(
TypeError: __init__() got an unexpected keyword argument 'filepath'
```


Discussion / hints:
@bohdan-huma Thank you for the interest.

Regarding the sampling part, you simply mean that you downloaded the file I provided in the README, right?

My best guess is that you have a version of `torch` or `torch-lightning` that breaks things. Could you please share what `pip freeze` gives in your environment. And also the Python version you are using.

Thank you in advance
@jankrepl thanks for a quick response
that is right, the zip were from the link provided in the README

```python -V``` gives me ```Python 3.9.4```

and here's the result of a ```pip freeze``` run
```
absl-py==1.0.0
aiohttp==3.8.1
aiosignal==1.2.0
async-timeout==4.0.2
attrs==21.4.0
bcrypt==3.2.0
cachetools==5.0.0
certifi==2021.5.30
cffi==1.15.0
charset-normalizer==2.0.4
click==8.0.4
cryptography==36.0.2
cycler==0.11.0
distro==1.7.0
docker==5.0.3
docker-compose==1.29.2
docker-compost==0.1
dockerpty==0.4.1
docopt==0.6.2
fonttools==4.31.1
frozenlist==1.3.0
fsspec==2022.2.0
future==0.18.2
google-auth==2.6.2
google-auth-oauthlib==0.4.6
grpcio==1.44.0
idna==3.2
importlib-metadata==4.11.3
jsonschema==3.2.0
kiwisolver==1.4.0
Markdown==3.3.6
matplotlib==3.5.1
mltype==0.1.1
multidict==6.0.2
networkx==2.7.1
numpy==1.22.3
oauthlib==3.2.0
packaging==21.3
paramiko==2.10.3
Pillow==9.0.1
protobuf==3.19.4
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.21
pyDeprecate==0.3.1
PyNaCl==1.5.0
pyparsing==3.0.7
pyrsistent==0.18.1
python-dateutil==2.8.2
python-dotenv==0.19.2
pytorch-lightning==1.5.10
PyYAML==5.4.1
requests==2.26.0
requests-oauthlib==1.3.1
rsa==4.8
six==1.16.0
tensorboard==2.8.0
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.1
texttable==1.6.4
torch==1.11.0
torchmetrics==0.7.2
tqdm==4.63.0
typing_extensions==4.1.1
urllib3==1.26.6
websocket-client==0.59.0
Werkzeug==2.0.3
yarl==1.7.2
zipp==3.7.0
```


Fix patch:
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 85b77fa..4d22023 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -1,6 +1,9 @@
 name: mltype
 
-on: [push, pull_request]
+on:
+  pull_request:
+  push:
+    branches: [master]
 
 jobs:
   build:
diff --git a/setup.py b/setup.py
index adb741b..3ba532d 100644
--- a/setup.py
+++ b/setup.py
@@ -10,7 +10,7 @@
     "click-config-file",
     "numpy",
     "torch",
-    "pytorch-lightning>=1.0.0",
+    "pytorch-lightning>=1.0.0,<1.2",
     "tqdm",
 ]
 


Test patch:
diff --git a/tests/test_base.py b/tests/test_base.py
index 9dc0c4d..c4a55a5 100644
--- a/tests/test_base.py
+++ b/tests/test_base.py
@@ -67,7 +67,6 @@ def test_basic(self):
         tt.type_character(1, "e")
 
         assert tt.elapsed_seconds > 0
-        assert tt.elapsed_seconds != tt.elapsed_seconds
 
         assert tt.n_characters == 5
         assert tt.n_correct_characters == 2