Add files using upload-large-folder tool
Browse files- checkpoints/aizynthfinder/uspto_model_onnx/SHA256SUMS +3 -3
- checkpoints/aizynthfinder/uspto_model_onnx/benchmarks/metadata.json +4 -4
- checkpoints/aizynthfinder/uspto_model_onnx/manifest.json +3 -3
- checkpoints/aizynthfinder/uspto_model_onnx/provenance.json +23 -31
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/SHA256SUMS +35 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/MAR-INF/MANIFEST.json +10 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/checkpoint_metadata.json +10 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/graph2smiles_runtime/predict.py +254 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/graph2smiles_runtime/train.py +287 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/graph2smiles_runtime/utils/c_calculate.so +0 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/graph2smiles_runtime/utils/chem_utils.py +144 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/graph2smiles_runtime/utils/ctypes_calculator.py +35 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/graph2smiles_runtime/utils/data_utils.py +512 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/graph2smiles_runtime/utils/parsing.py +120 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/graph2smiles_runtime/utils/preprocess_utils.py +153 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/graph2smiles_runtime/utils/rxn_graphs.py +196 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/graph2smiles_runtime/utils/train_utils.py +111 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/mar_files/handler.py +278 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/mar_files/predict.py +254 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/mar_files/train.py +287 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/mar_files/vocab.txt +518 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/mar_members.json +52 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/model_args.json +79 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/safetensors_conversion.json +14 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/vocab.txt +518 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/benchmarks/default_test.jsonl +0 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/benchmarks/metadata.json +15 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/manifest.json +162 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/provenance.json +108 -0
- checkpoints/askcos_retro_graph2smiles/pistachio_23q3/wrapper_config.json +49 -0
- checkpoints/askcos_retro_graph2smiles/uspto_full/SHA256SUMS +37 -0
- checkpoints/askcos_retro_graph2smiles/uspto_full/manifest.json +168 -0
- checkpoints/askcos_retro_graph2smiles/uspto_full/provenance.json +108 -0
- checkpoints/askcos_retro_graph2smiles/uspto_full/wrapper_config.json +49 -0
checkpoints/aizynthfinder/uspto_model_onnx/SHA256SUMS
CHANGED
|
@@ -2,10 +2,10 @@
|
|
| 2 |
ad29aa32bdfcbe37065045546493806cf04899c55386c438905d83fb14bb6320 aux/uspto_filter_model.onnx
|
| 3 |
a4f1945e90cfa195538320833d68aed38f14e2fcc2f8afb5d958bc920edcafbe aux/uspto_templates.csv.gz
|
| 4 |
a10255a6abd89a35d2ea48a842839f403b4b1586805c3010c0d076e0ae23754d benchmarks/default_test.jsonl
|
| 5 |
-
|
| 6 |
87d7e0013f97da27e4fd878b0598466ac07202fe131ac0f7dbdd2b423482751f benchmarks/native/ref_routes_reaction_hashes.txt
|
| 7 |
872533b44788754af3aa19918a04c2a508d30249d2c93eb480078cb638ad3389 benchmarks/native/selected_reactions.csv
|
| 8 |
-
|
| 9 |
bd0a3cb74cd7068de474c8fb789a00a66bc42c75636d66510ccac585ebe928f8 model.onnx
|
| 10 |
-
|
| 11 |
332fcbbe37447c13381f5cf58baa2431a2dca96e66ef3d1e8562624b916b7a67 wrapper_config.json
|
|
|
|
| 2 |
ad29aa32bdfcbe37065045546493806cf04899c55386c438905d83fb14bb6320 aux/uspto_filter_model.onnx
|
| 3 |
a4f1945e90cfa195538320833d68aed38f14e2fcc2f8afb5d958bc920edcafbe aux/uspto_templates.csv.gz
|
| 4 |
a10255a6abd89a35d2ea48a842839f403b4b1586805c3010c0d076e0ae23754d benchmarks/default_test.jsonl
|
| 5 |
+
5c272a6819a4315094e57ad2d63712133a202c778a03fd7c3597e1b459b44224 benchmarks/metadata.json
|
| 6 |
87d7e0013f97da27e4fd878b0598466ac07202fe131ac0f7dbdd2b423482751f benchmarks/native/ref_routes_reaction_hashes.txt
|
| 7 |
872533b44788754af3aa19918a04c2a508d30249d2c93eb480078cb638ad3389 benchmarks/native/selected_reactions.csv
|
| 8 |
+
3a4cf47b5bc0f374bc7cf3851fa2ef3a5ea8440d52eb9a72e7127f9f754717b8 manifest.json
|
| 9 |
bd0a3cb74cd7068de474c8fb789a00a66bc42c75636d66510ccac585ebe928f8 model.onnx
|
| 10 |
+
a201615c60a1fc9ddab93b85d54101d1068a344e42b448a8f2c8925fc3b335f9 provenance.json
|
| 11 |
332fcbbe37447c13381f5cf58baa2431a2dca96e66ef3d1e8562624b916b7a67 wrapper_config.json
|
checkpoints/aizynthfinder/uspto_model_onnx/benchmarks/metadata.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
| 10 |
"notes": [
|
| 11 |
"This is the PaRoutes selected_reactions.csv source table used to reconstruct the held-out reference-route reaction subset."
|
| 12 |
],
|
| 13 |
-
"origin": "
|
| 14 |
"relative_path": "benchmarks/native/selected_reactions.csv",
|
| 15 |
"source_url": "https://zenodo.org/records/7341155/files/selected_reactions.csv?download=1"
|
| 16 |
},
|
|
@@ -18,7 +18,7 @@
|
|
| 18 |
"notes": [
|
| 19 |
"This hash list identifies the exact AiZynthTrain/PaRoutes reference reactions held out for testing."
|
| 20 |
],
|
| 21 |
-
"origin": "
|
| 22 |
"relative_path": "benchmarks/native/ref_routes_reaction_hashes.txt",
|
| 23 |
"source_url": "https://zenodo.org/records/7341155/files/ref_routes_reaction_hashes.txt?download=1"
|
| 24 |
}
|
|
@@ -28,7 +28,7 @@
|
|
| 28 |
"The benchmark rows are reconstructed from PaRoutes selected_reactions.csv and ref_routes_reaction_hashes.txt so they match the held-out reference-route reactions used as the AiZynthTrain test set."
|
| 29 |
],
|
| 30 |
"num_examples": 56657,
|
| 31 |
-
"source_reference_hashes_path": "datasets/
|
| 32 |
-
"source_selected_reactions_path": "datasets/
|
| 33 |
"split": "test"
|
| 34 |
}
|
|
|
|
| 10 |
"notes": [
|
| 11 |
"This is the PaRoutes selected_reactions.csv source table used to reconstruct the held-out reference-route reaction subset."
|
| 12 |
],
|
| 13 |
+
"origin": "copied_from_local_public_record",
|
| 14 |
"relative_path": "benchmarks/native/selected_reactions.csv",
|
| 15 |
"source_url": "https://zenodo.org/records/7341155/files/selected_reactions.csv?download=1"
|
| 16 |
},
|
|
|
|
| 18 |
"notes": [
|
| 19 |
"This hash list identifies the exact AiZynthTrain/PaRoutes reference reactions held out for testing."
|
| 20 |
],
|
| 21 |
+
"origin": "copied_from_local_public_record",
|
| 22 |
"relative_path": "benchmarks/native/ref_routes_reaction_hashes.txt",
|
| 23 |
"source_url": "https://zenodo.org/records/7341155/files/ref_routes_reaction_hashes.txt?download=1"
|
| 24 |
}
|
|
|
|
| 28 |
"The benchmark rows are reconstructed from PaRoutes selected_reactions.csv and ref_routes_reaction_hashes.txt so they match the held-out reference-route reactions used as the AiZynthTrain test set."
|
| 29 |
],
|
| 30 |
"num_examples": 56657,
|
| 31 |
+
"source_reference_hashes_path": "datasets/paroutes_public_data/ref_routes_reaction_hashes.txt",
|
| 32 |
+
"source_selected_reactions_path": "datasets/paroutes_public_data/selected_reactions.csv",
|
| 33 |
"split": "test"
|
| 34 |
}
|
checkpoints/aizynthfinder/uspto_model_onnx/manifest.json
CHANGED
|
@@ -35,7 +35,7 @@
|
|
| 35 |
{
|
| 36 |
"canonical_split_family": "aizynthtrain_uspto_selected_reactions_paroutes_reference_holdout",
|
| 37 |
"dataset_ref": "aizynthtrain_uspto_selected_reactions_with_paroutes_holdout",
|
| 38 |
-
"path": "
|
| 39 |
"split_names": [
|
| 40 |
"train",
|
| 41 |
"val",
|
|
@@ -89,7 +89,7 @@
|
|
| 89 |
{
|
| 90 |
"canonical_split_family": "aizynthtrain_uspto_selected_reactions_paroutes_reference_holdout",
|
| 91 |
"dataset_ref": "aizynthtrain_uspto_selected_reactions_with_paroutes_holdout",
|
| 92 |
-
"path": "
|
| 93 |
"split_names": [
|
| 94 |
"train",
|
| 95 |
"val",
|
|
@@ -115,7 +115,7 @@
|
|
| 115 |
{
|
| 116 |
"canonical_split_family": "aizynthtrain_uspto_selected_reactions_paroutes_reference_holdout",
|
| 117 |
"dataset_ref": "aizynthtrain_uspto_selected_reactions_with_paroutes_holdout",
|
| 118 |
-
"path": "
|
| 119 |
"split_names": [
|
| 120 |
"train",
|
| 121 |
"val",
|
|
|
|
| 35 |
{
|
| 36 |
"canonical_split_family": "aizynthtrain_uspto_selected_reactions_paroutes_reference_holdout",
|
| 37 |
"dataset_ref": "aizynthtrain_uspto_selected_reactions_with_paroutes_holdout",
|
| 38 |
+
"path": "aizynthfinder_public_data/uspto_model.onnx",
|
| 39 |
"split_names": [
|
| 40 |
"train",
|
| 41 |
"val",
|
|
|
|
| 89 |
{
|
| 90 |
"canonical_split_family": "aizynthtrain_uspto_selected_reactions_paroutes_reference_holdout",
|
| 91 |
"dataset_ref": "aizynthtrain_uspto_selected_reactions_with_paroutes_holdout",
|
| 92 |
+
"path": "aizynthfinder_public_data/uspto_model.onnx",
|
| 93 |
"split_names": [
|
| 94 |
"train",
|
| 95 |
"val",
|
|
|
|
| 115 |
{
|
| 116 |
"canonical_split_family": "aizynthtrain_uspto_selected_reactions_paroutes_reference_holdout",
|
| 117 |
"dataset_ref": "aizynthtrain_uspto_selected_reactions_with_paroutes_holdout",
|
| 118 |
+
"path": "aizynthfinder_public_data/uspto_model.onnx",
|
| 119 |
"split_names": [
|
| 120 |
"train",
|
| 121 |
"val",
|
checkpoints/aizynthfinder/uspto_model_onnx/provenance.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
{
|
| 2 |
"conversion_notes": [
|
| 3 |
"Copied the public AiZynthFinder USPTO ONNX policy graph verbatim into model.onnx.",
|
| 4 |
-
"Bundled the matching public template CSV and optional filter/config sidecars from
|
| 5 |
],
|
| 6 |
"copied_sidecars": [
|
| 7 |
"aux/config.yml",
|
|
@@ -12,100 +12,92 @@
|
|
| 12 |
"normalized_checkpoint_id": "uspto_model_onnx",
|
| 13 |
"source_artifacts": [
|
| 14 |
{
|
| 15 |
-
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/
|
| 16 |
"kind": "local_repo_file",
|
| 17 |
-
"path": "datasets/
|
| 18 |
"role": "source_artifact",
|
| 19 |
"sha256": "51243c4b1b0a7fa4908bd8dd06de9690ea4b87d0c856caaf419a0cec32cd5da4",
|
| 20 |
"size": 335
|
| 21 |
},
|
| 22 |
{
|
| 23 |
-
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/
|
| 24 |
"kind": "local_repo_file",
|
| 25 |
-
"path": "datasets/
|
| 26 |
"role": "source_artifact",
|
| 27 |
"sha256": "014690b9f1aeb49e14c7c64da0060e371e3760090a37abe7033fadcc24ee2992",
|
| 28 |
"size": 755
|
| 29 |
},
|
| 30 |
{
|
| 31 |
-
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/
|
| 32 |
"kind": "local_repo_file",
|
| 33 |
-
"path": "datasets/
|
| 34 |
"role": "source_artifact",
|
| 35 |
"sha256": "922282e9943f9b7070865d685c4cd8f46b507028f4a0e295c3034eda9c4bd21f",
|
| 36 |
"size": 50392960
|
| 37 |
},
|
| 38 |
{
|
| 39 |
-
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/
|
| 40 |
"kind": "local_repo_file",
|
| 41 |
-
"path": "datasets/
|
| 42 |
"role": "source_artifact",
|
| 43 |
"sha256": "ad29aa32bdfcbe37065045546493806cf04899c55386c438905d83fb14bb6320",
|
| 44 |
"size": 16788859
|
| 45 |
},
|
| 46 |
{
|
| 47 |
-
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/
|
| 48 |
"kind": "local_repo_file",
|
| 49 |
-
"path": "datasets/
|
| 50 |
"role": "source_artifact",
|
| 51 |
"sha256": "75f87cc726271535868fbf3cbf9b7ac34fc97fd7540be2e3c61c1ad48c1bb4d2",
|
| 52 |
"size": 274578664
|
| 53 |
},
|
| 54 |
{
|
| 55 |
-
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/
|
| 56 |
"kind": "local_repo_file",
|
| 57 |
-
"path": "datasets/
|
| 58 |
"role": "source_artifact",
|
| 59 |
"sha256": "bd0a3cb74cd7068de474c8fb789a00a66bc42c75636d66510ccac585ebe928f8",
|
| 60 |
"size": 91518243
|
| 61 |
},
|
| 62 |
{
|
| 63 |
-
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/
|
| 64 |
"kind": "local_repo_file",
|
| 65 |
-
"path": "datasets/
|
| 66 |
"role": "source_artifact",
|
| 67 |
"sha256": "0faac874ea4c8b149aeba35479eb9063c8349fd33500d33a83db3e068bba70ad",
|
| 68 |
"size": 45132232
|
| 69 |
},
|
| 70 |
{
|
| 71 |
-
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/
|
| 72 |
"kind": "local_repo_file",
|
| 73 |
-
"path": "datasets/
|
| 74 |
"role": "source_artifact",
|
| 75 |
"sha256": "1bf0690352d9e9212d7dbe8b35649caf74f73ef0b30edefdfdac37fce38085be",
|
| 76 |
"size": 15036094
|
| 77 |
},
|
| 78 |
{
|
| 79 |
-
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/
|
| 80 |
"kind": "local_repo_file",
|
| 81 |
-
"path": "datasets/
|
| 82 |
"role": "source_artifact",
|
| 83 |
"sha256": "5616a056454b10a2f044e69e027422128986856ebd958541a3bf9f837e3a0d14",
|
| 84 |
"size": 373753
|
| 85 |
},
|
| 86 |
{
|
| 87 |
-
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/
|
| 88 |
"kind": "local_repo_file",
|
| 89 |
-
"path": "datasets/
|
| 90 |
"role": "source_artifact",
|
| 91 |
"sha256": "a4f1945e90cfa195538320833d68aed38f14e2fcc2f8afb5d958bc920edcafbe",
|
| 92 |
"size": 3313598
|
| 93 |
},
|
| 94 |
{
|
| 95 |
-
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/
|
| 96 |
"kind": "local_repo_file",
|
| 97 |
-
"path": "datasets/
|
| 98 |
"role": "source_artifact",
|
| 99 |
"sha256": "ff54c334c3dfc11882d5fa3024fde3be8cf3e38f979d93a39b9be8cca1a5dc85",
|
| 100 |
"size": 1339073560
|
| 101 |
-
},
|
| 102 |
-
{
|
| 103 |
-
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/download_aizynthfinder_11430881.sh",
|
| 104 |
-
"kind": "local_repo_file",
|
| 105 |
-
"path": "datasets/download_aizynthfinder_11430881.sh",
|
| 106 |
-
"role": "source_artifact",
|
| 107 |
-
"sha256": "6b9fb80d96a0e3b8c1ea2d484e2e2587ed53ae21c6ebea512608d523fbdce014",
|
| 108 |
-
"size": 977
|
| 109 |
}
|
| 110 |
]
|
| 111 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"conversion_notes": [
|
| 3 |
"Copied the public AiZynthFinder USPTO ONNX policy graph verbatim into model.onnx.",
|
| 4 |
+
"Bundled the matching public template CSV and optional filter/config sidecars from Public record 11430881."
|
| 5 |
],
|
| 6 |
"copied_sidecars": [
|
| 7 |
"aux/config.yml",
|
|
|
|
| 12 |
"normalized_checkpoint_id": "uspto_model_onnx",
|
| 13 |
"source_artifacts": [
|
| 14 |
{
|
| 15 |
+
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/aizynthfinder_public_data/config.yml",
|
| 16 |
"kind": "local_repo_file",
|
| 17 |
+
"path": "datasets/aizynthfinder_public_data/config.yml",
|
| 18 |
"role": "source_artifact",
|
| 19 |
"sha256": "51243c4b1b0a7fa4908bd8dd06de9690ea4b87d0c856caaf419a0cec32cd5da4",
|
| 20 |
"size": 335
|
| 21 |
},
|
| 22 |
{
|
| 23 |
+
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/aizynthfinder_public_data/urls.txt",
|
| 24 |
"kind": "local_repo_file",
|
| 25 |
+
"path": "datasets/aizynthfinder_public_data/urls.txt",
|
| 26 |
"role": "source_artifact",
|
| 27 |
"sha256": "014690b9f1aeb49e14c7c64da0060e371e3760090a37abe7033fadcc24ee2992",
|
| 28 |
"size": 755
|
| 29 |
},
|
| 30 |
{
|
| 31 |
+
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/aizynthfinder_public_data/uspto_filter_model.hdf5",
|
| 32 |
"kind": "local_repo_file",
|
| 33 |
+
"path": "datasets/aizynthfinder_public_data/uspto_filter_model.hdf5",
|
| 34 |
"role": "source_artifact",
|
| 35 |
"sha256": "922282e9943f9b7070865d685c4cd8f46b507028f4a0e295c3034eda9c4bd21f",
|
| 36 |
"size": 50392960
|
| 37 |
},
|
| 38 |
{
|
| 39 |
+
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/aizynthfinder_public_data/uspto_filter_model.onnx",
|
| 40 |
"kind": "local_repo_file",
|
| 41 |
+
"path": "datasets/aizynthfinder_public_data/uspto_filter_model.onnx",
|
| 42 |
"role": "source_artifact",
|
| 43 |
"sha256": "ad29aa32bdfcbe37065045546493806cf04899c55386c438905d83fb14bb6320",
|
| 44 |
"size": 16788859
|
| 45 |
},
|
| 46 |
{
|
| 47 |
+
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/aizynthfinder_public_data/uspto_model.hdf5",
|
| 48 |
"kind": "local_repo_file",
|
| 49 |
+
"path": "datasets/aizynthfinder_public_data/uspto_model.hdf5",
|
| 50 |
"role": "source_artifact",
|
| 51 |
"sha256": "75f87cc726271535868fbf3cbf9b7ac34fc97fd7540be2e3c61c1ad48c1bb4d2",
|
| 52 |
"size": 274578664
|
| 53 |
},
|
| 54 |
{
|
| 55 |
+
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/aizynthfinder_public_data/uspto_model.onnx",
|
| 56 |
"kind": "local_repo_file",
|
| 57 |
+
"path": "datasets/aizynthfinder_public_data/uspto_model.onnx",
|
| 58 |
"role": "source_artifact",
|
| 59 |
"sha256": "bd0a3cb74cd7068de474c8fb789a00a66bc42c75636d66510ccac585ebe928f8",
|
| 60 |
"size": 91518243
|
| 61 |
},
|
| 62 |
{
|
| 63 |
+
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/aizynthfinder_public_data/uspto_ringbreaker_model.hdf5",
|
| 64 |
"kind": "local_repo_file",
|
| 65 |
+
"path": "datasets/aizynthfinder_public_data/uspto_ringbreaker_model.hdf5",
|
| 66 |
"role": "source_artifact",
|
| 67 |
"sha256": "0faac874ea4c8b149aeba35479eb9063c8349fd33500d33a83db3e068bba70ad",
|
| 68 |
"size": 45132232
|
| 69 |
},
|
| 70 |
{
|
| 71 |
+
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/aizynthfinder_public_data/uspto_ringbreaker_model.onnx",
|
| 72 |
"kind": "local_repo_file",
|
| 73 |
+
"path": "datasets/aizynthfinder_public_data/uspto_ringbreaker_model.onnx",
|
| 74 |
"role": "source_artifact",
|
| 75 |
"sha256": "1bf0690352d9e9212d7dbe8b35649caf74f73ef0b30edefdfdac37fce38085be",
|
| 76 |
"size": 15036094
|
| 77 |
},
|
| 78 |
{
|
| 79 |
+
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/aizynthfinder_public_data/uspto_ringbreaker_templates.csv.gz",
|
| 80 |
"kind": "local_repo_file",
|
| 81 |
+
"path": "datasets/aizynthfinder_public_data/uspto_ringbreaker_templates.csv.gz",
|
| 82 |
"role": "source_artifact",
|
| 83 |
"sha256": "5616a056454b10a2f044e69e027422128986856ebd958541a3bf9f837e3a0d14",
|
| 84 |
"size": 373753
|
| 85 |
},
|
| 86 |
{
|
| 87 |
+
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/aizynthfinder_public_data/uspto_templates.csv.gz",
|
| 88 |
"kind": "local_repo_file",
|
| 89 |
+
"path": "datasets/aizynthfinder_public_data/uspto_templates.csv.gz",
|
| 90 |
"role": "source_artifact",
|
| 91 |
"sha256": "a4f1945e90cfa195538320833d68aed38f14e2fcc2f8afb5d958bc920edcafbe",
|
| 92 |
"size": 3313598
|
| 93 |
},
|
| 94 |
{
|
| 95 |
+
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/aizynthfinder_public_data/zinc_stock.hdf5",
|
| 96 |
"kind": "local_repo_file",
|
| 97 |
+
"path": "datasets/aizynthfinder_public_data/zinc_stock.hdf5",
|
| 98 |
"role": "source_artifact",
|
| 99 |
"sha256": "ff54c334c3dfc11882d5fa3024fde3be8cf3e38f979d93a39b9be8cca1a5dc85",
|
| 100 |
"size": 1339073560
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
}
|
| 102 |
]
|
| 103 |
}
|
checkpoints/askcos_retro_graph2smiles/pistachio_23q3/SHA256SUMS
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
2e1d66780fd41703250f7178778e0ed5f52e00b5bc00fc9a94a403551e62602e aux/MAR-INF/MANIFEST.json
|
| 2 |
+
228e2ef709b47fddf7290de52f4c2462c7d44bee856f83aa1ed94f3732693be7 aux/checkpoint_metadata.json
|
| 3 |
+
b7f0a220dcbb261ea2dc3ac8e16c86a4b508cf012da5d5e250ab82c0dcbb9794 aux/graph2smiles_runtime/models/attention_xl.py
|
| 4 |
+
59e5e707bf6298eaa63fccfcb638719f280579b08ccc969bb3075c2a07a9cc22 aux/graph2smiles_runtime/models/dgat.py
|
| 5 |
+
0f9c77867fa1a53c18d893dab68a57f94bbaa326f8ff63e374860c45a11b1e6c aux/graph2smiles_runtime/models/dgcn.py
|
| 6 |
+
26260eb71e0da0f998d63c391641a6aa782171ed0c670c4f07014402a5073ff5 aux/graph2smiles_runtime/models/graph2smiles.py
|
| 7 |
+
fbbbec61d02ddb6b9d90720b2d5b0a04a399a0abe9b1575ed4f8d428a7638f75 aux/graph2smiles_runtime/models/graphfeat.py
|
| 8 |
+
3b85acd86c407470536395cf85b8af99dc067f67f31897c42dc00f4a32f772c3 aux/graph2smiles_runtime/models/model_utils.py
|
| 9 |
+
d5c87645c9f7ebc96d23d3ae94c8692ffcd798e60e2b52d6d876505752eb007b aux/graph2smiles_runtime/models/transformer_decoder.py
|
| 10 |
+
9309e0352e4fb7f6c00b8dccd1bd4300ed91f7660533e3ace9db8e61645caa26 aux/graph2smiles_runtime/predict.py
|
| 11 |
+
fb3b0374bcf3773e87926bce4160aa30bd9088e71b56b3daa617de2cb03892fa aux/graph2smiles_runtime/train.py
|
| 12 |
+
f7e98befeb3a532d72595f3f64728dbf32d2daa8ba91ad8e451eed16e31d244b aux/graph2smiles_runtime/utils/c_calculate.so
|
| 13 |
+
2f440d3b147d5eb16158a0eff7872bf54939a77f73d5569d229fac82f3e640d3 aux/graph2smiles_runtime/utils/chem_utils.py
|
| 14 |
+
458944b4a15fb16f0da33e4e71b790815e2f88d49b5babf3b44a82d51a737422 aux/graph2smiles_runtime/utils/ctypes_calculator.py
|
| 15 |
+
7a671fbff8a4c202c33af82fe2708f848a4aa07526ef7d90536ff655c77700ef aux/graph2smiles_runtime/utils/data_utils.py
|
| 16 |
+
4b2c0587180c996e160581861b8c6dae0dfde8dc8fd0f4112bb0b07704a168b4 aux/graph2smiles_runtime/utils/parsing.py
|
| 17 |
+
0440ec0b6cee9da8e64b4397b83c6a1672ac3d134565c9aa7b758fd174c4fdf9 aux/graph2smiles_runtime/utils/preprocess_utils.py
|
| 18 |
+
50e105d0a95fab34653c0ddc134bda5324f5825b3ce907d6349183f34d38627d aux/graph2smiles_runtime/utils/rxn_graphs.py
|
| 19 |
+
5474b2518dceaaa121aef3e4656d808d3f1dc73161eff0139277bc7f0c021ab3 aux/graph2smiles_runtime/utils/train_utils.py
|
| 20 |
+
5553c34645ededd4e2012700cc0436ba54b061c3c7e97011e23b21c4eb05bfe8 aux/mar_files/handler.py
|
| 21 |
+
a41171f185ba73107f02c9d9799767302cdcae4644900b8b07d882e9ac733d5c aux/mar_files/models.zip
|
| 22 |
+
9309e0352e4fb7f6c00b8dccd1bd4300ed91f7660533e3ace9db8e61645caa26 aux/mar_files/predict.py
|
| 23 |
+
fb3b0374bcf3773e87926bce4160aa30bd9088e71b56b3daa617de2cb03892fa aux/mar_files/train.py
|
| 24 |
+
935b416024acc35678b82e34bbe023c6d38af0b77fd52a3b00867a143fd01f25 aux/mar_files/utils.zip
|
| 25 |
+
ac9d2a64c0d30a7eb04b28f3bf31db8dd6cc961b22cd75afa0d76c6e2cd39126 aux/mar_files/vocab.txt
|
| 26 |
+
31b461de0d6a05e238cfbf075582cd1a4e7a5f5b6c8338fabacdc65c22a62a53 aux/mar_members.json
|
| 27 |
+
ae3774a5ea8b644523546904afc23078a6a0bf237199cfb993f34b90bbaae68f aux/model_args.json
|
| 28 |
+
07c37c91ceb6a19eebabdd5b83315b7deceb4ff7c5a88dd41d76bf022c1a227c aux/safetensors_conversion.json
|
| 29 |
+
ac9d2a64c0d30a7eb04b28f3bf31db8dd6cc961b22cd75afa0d76c6e2cd39126 aux/vocab.txt
|
| 30 |
+
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 benchmarks/default_test.jsonl
|
| 31 |
+
cde971b8b51cc957662564f1082fe946d944bb16b6008ec20c5efbcda55bba4a benchmarks/metadata.json
|
| 32 |
+
7c951b8e1ce8f66298de4ce8c5667df5a0b92b76c70cf687a0e327de209f074e manifest.json
|
| 33 |
+
98105ab007959ddbb96e72d5bed1e968cc31cc62fe7f937c5140edc5febb2bb3 model.safetensors
|
| 34 |
+
a06909c865f0fa89789d273b731ead8199eb49843f62cd39716dd1b968a43189 provenance.json
|
| 35 |
+
d57e04e070323555022ffe938ff86af5e8e8373b28440c0884482509d65b9e93 wrapper_config.json
|
checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/MAR-INF/MANIFEST.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"archiverVersion": "0.3.1",
|
| 3 |
+
"createdOn": "19/10/2024 01:31:37",
|
| 4 |
+
"model": {
|
| 5 |
+
"handler": "handler.py",
|
| 6 |
+
"modelName": "pistachio_clean_Q3",
|
| 7 |
+
"modelVersion": "1.0"
|
| 8 |
+
},
|
| 9 |
+
"runtime": "python"
|
| 10 |
+
}
|
checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/checkpoint_metadata.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import datetime
|
| 3 |
+
import glob
|
| 4 |
+
import numpy as np
|
| 5 |
+
import os
|
| 6 |
+
import sys
|
| 7 |
+
import time
|
| 8 |
+
import torch
|
| 9 |
+
import torch.distributed as dist
|
| 10 |
+
from models.graph2smiles import Graph2SMILES
|
| 11 |
+
from torch.utils.data import DataLoader, SequentialSampler
|
| 12 |
+
from torch.utils.data.distributed import DistributedSampler
|
| 13 |
+
from train import get_model
|
| 14 |
+
from utils import parsing
|
| 15 |
+
from utils.data_utils import canonicalize_smiles, load_vocab, G2SDataset
|
| 16 |
+
from utils.train_utils import log_tensor, log_rank_0, param_count, set_seed, setup_logger
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def get_predict_parser():
|
| 20 |
+
parser = argparse.ArgumentParser("predict")
|
| 21 |
+
parsing.add_common_args(parser)
|
| 22 |
+
parsing.add_preprocess_args(parser)
|
| 23 |
+
parsing.add_train_args(parser)
|
| 24 |
+
parsing.add_predict_args(parser)
|
| 25 |
+
|
| 26 |
+
return parser
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def get_predictions(args, model, vocab_tokens, test_loader, device, start, multiplier=1):
|
| 30 |
+
all_predictions = []
|
| 31 |
+
|
| 32 |
+
log_rank_0(f"nbest = {(args.n_best * multiplier)}")
|
| 33 |
+
|
| 34 |
+
with torch.no_grad():
|
| 35 |
+
for test_idx, test_batch in enumerate(test_loader):
|
| 36 |
+
if test_idx % args.log_iter == 0:
|
| 37 |
+
log_rank_0(f"Doing inference on test step {test_idx}, "
|
| 38 |
+
f"time: {time.time() - start: .2f} s")
|
| 39 |
+
|
| 40 |
+
test_batch.to(device)
|
| 41 |
+
results = model.predict_step(
|
| 42 |
+
reaction_batch=test_batch,
|
| 43 |
+
batch_size=test_batch.size,
|
| 44 |
+
beam_size=args.beam_size,
|
| 45 |
+
n_best=args.n_best * multiplier,
|
| 46 |
+
temperature=args.temperature,
|
| 47 |
+
min_length=args.predict_min_len,
|
| 48 |
+
max_length=args.predict_max_len
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
for predictions, scores in zip(results["predictions"], results["scores"]):
|
| 52 |
+
smis_with_scores = []
|
| 53 |
+
for prediction, score in zip(predictions, scores):
|
| 54 |
+
predicted_idx = prediction.detach().cpu().numpy()
|
| 55 |
+
score = score.detach().cpu().numpy()
|
| 56 |
+
predicted_tokens = [vocab_tokens[idx] for idx in predicted_idx[:-1]]
|
| 57 |
+
smi = "".join(predicted_tokens)
|
| 58 |
+
smis_with_scores.append(f"{smi}_{score}")
|
| 59 |
+
smis_with_scores = ",".join(smis_with_scores)
|
| 60 |
+
all_predictions.append(f"{smis_with_scores}\n")
|
| 61 |
+
|
| 62 |
+
return all_predictions
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def main(args):
|
| 66 |
+
args.device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
| 67 |
+
device = args.device
|
| 68 |
+
if args.local_rank != -1:
|
| 69 |
+
dist.init_process_group(backend=args.backend, init_method='env://', timeout=datetime.timedelta(0, 7200))
|
| 70 |
+
torch.cuda.set_device(args.local_rank)
|
| 71 |
+
torch.backends.cudnn.benchmark = True
|
| 72 |
+
|
| 73 |
+
if torch.distributed.is_initialized():
|
| 74 |
+
log_rank_0(f"Device rank: {torch.distributed.get_rank()}")
|
| 75 |
+
os.makedirs(os.path.join("./results", args.data_name), exist_ok=True)
|
| 76 |
+
# os.makedirs(os.path.join("./results", args.test_output_path), exist_ok=True)
|
| 77 |
+
|
| 78 |
+
parsing.log_args(args, phase="prediction")
|
| 79 |
+
|
| 80 |
+
# initialization ---------------------------------- ckpt parsing
|
| 81 |
+
if args.do_validate:
|
| 82 |
+
checkpoints = glob.glob(os.path.join(args.load_from, "*.pt"))
|
| 83 |
+
checkpoints = sorted(
|
| 84 |
+
checkpoints,
|
| 85 |
+
key=lambda ckpt: int(ckpt.split(".")[-2].split("_")[-1]),
|
| 86 |
+
reverse=True
|
| 87 |
+
)
|
| 88 |
+
multipliers = [3] * len(checkpoints)
|
| 89 |
+
checkpoints = [ckpt for ckpt in checkpoints
|
| 90 |
+
if (args.checkpoint_step_start <= int(ckpt.split(".")[-2].split("_")[1]))
|
| 91 |
+
and (args.checkpoint_step_end >= int(ckpt.split(".")[-2].split("_")[1]))]
|
| 92 |
+
file_bin = os.path.join(args.processed_data_path, "val.npz")
|
| 93 |
+
file_tgt = os.path.join(args.processed_data_path, "tgt-val.txt")
|
| 94 |
+
elif args.do_predict:
|
| 95 |
+
# multipliers = [1, 3, 5, 10, 20]
|
| 96 |
+
multipliers = [3]
|
| 97 |
+
checkpoints = [os.path.join(args.model_path, args.load_from)]
|
| 98 |
+
file_bin = os.path.join(args.processed_data_path, "test.npz")
|
| 99 |
+
file_tgt = os.path.join(args.processed_data_path, "tgt-test.txt")
|
| 100 |
+
else:
|
| 101 |
+
raise ValueError("Either --do_validate or --do_predict need to be specified!")
|
| 102 |
+
|
| 103 |
+
model = None
|
| 104 |
+
test_dataset = None
|
| 105 |
+
vocab_tokens = None
|
| 106 |
+
smis_tgt = []
|
| 107 |
+
start = time.time()
|
| 108 |
+
for ckpt_i, checkpoint in enumerate(checkpoints):
|
| 109 |
+
result_file = os.path.join(args.test_output_path, f"result.{ckpt_i}")
|
| 110 |
+
result_stat_file = os.path.join(args.test_output_path, f"result.stat.{ckpt_i}")
|
| 111 |
+
|
| 112 |
+
if os.path.exists(result_file) and False:
|
| 113 |
+
log_rank_0(f"Result file found at {result_file}, skipping prediction.")
|
| 114 |
+
else:
|
| 115 |
+
log_rank_0(f"Loading from {checkpoint}")
|
| 116 |
+
try:
|
| 117 |
+
state = torch.load(checkpoint)
|
| 118 |
+
except RuntimeError:
|
| 119 |
+
log_rank_0(f"Error loading {checkpoint}, skipping")
|
| 120 |
+
continue # some weird corrupted files
|
| 121 |
+
|
| 122 |
+
pretrain_args = state["args"]
|
| 123 |
+
pretrain_args.load_from = None
|
| 124 |
+
pretrain_state_dict = state["state_dict"]
|
| 125 |
+
pretrain_args.local_rank = args.local_rank
|
| 126 |
+
if not hasattr(pretrain_args, "n_latent"):
|
| 127 |
+
pretrain_args.n_latent = 1
|
| 128 |
+
args.n_latent = pretrain_args.n_latent
|
| 129 |
+
if not hasattr(pretrain_args, "shared_attention_layer"):
|
| 130 |
+
pretrain_args.shared_attention_layer = 0
|
| 131 |
+
|
| 132 |
+
if model is None:
|
| 133 |
+
# initialization ---------------------------------- model
|
| 134 |
+
log_rank_0("Model is None, building model")
|
| 135 |
+
log_rank_0("First logging args for training")
|
| 136 |
+
parsing.log_args(pretrain_args, phase="training")
|
| 137 |
+
|
| 138 |
+
# backward
|
| 139 |
+
assert args.model == pretrain_args.model or \
|
| 140 |
+
pretrain_args.model == "g2s_series_rel", \
|
| 141 |
+
f"Pretrained model is {pretrain_args.model}!"
|
| 142 |
+
model_class = Graph2SMILES
|
| 143 |
+
dataset_class = G2SDataset
|
| 144 |
+
args.compute_graph_distance = True
|
| 145 |
+
|
| 146 |
+
# initialization ---------------------------------- vocab
|
| 147 |
+
vocab = load_vocab(args)
|
| 148 |
+
vocab_tokens = [k for k, v in sorted(vocab.items(), key=lambda tup: tup[1])]
|
| 149 |
+
|
| 150 |
+
model, state = get_model(pretrain_args, model_class, vocab, device)
|
| 151 |
+
if hasattr(model, "module"):
|
| 152 |
+
model = model.module # unwrap DDP model to enable accessing model func directly
|
| 153 |
+
|
| 154 |
+
log_rank_0(model)
|
| 155 |
+
log_rank_0(f"Number of parameters = {param_count(model)}")
|
| 156 |
+
|
| 157 |
+
# initialization ---------------------------------- data
|
| 158 |
+
test_dataset = dataset_class(args, file=file_bin)
|
| 159 |
+
test_dataset.batch(
|
| 160 |
+
batch_type=args.batch_type,
|
| 161 |
+
batch_size=args.predict_batch_size
|
| 162 |
+
)
|
| 163 |
+
with open(file_tgt, "r") as f:
|
| 164 |
+
total = sum(1 for _ in f)
|
| 165 |
+
|
| 166 |
+
with open(file_tgt, "r") as f:
|
| 167 |
+
for line_tgt in f:
|
| 168 |
+
smi_tgt = "".join(line_tgt.split())
|
| 169 |
+
smi_tgt = canonicalize_smiles(smi_tgt)
|
| 170 |
+
smis_tgt.append(smi_tgt)
|
| 171 |
+
|
| 172 |
+
pretrain_state_dict = {k.replace("module.", ""): v for k, v in pretrain_state_dict.items()}
|
| 173 |
+
model.load_state_dict(pretrain_state_dict)
|
| 174 |
+
log_rank_0(f"Loaded pretrained state_dict from {checkpoint}")
|
| 175 |
+
model.eval()
|
| 176 |
+
|
| 177 |
+
if args.local_rank != -1:
|
| 178 |
+
test_sampler = DistributedSampler(test_dataset, shuffle=False)
|
| 179 |
+
else:
|
| 180 |
+
test_sampler = SequentialSampler(test_dataset)
|
| 181 |
+
|
| 182 |
+
test_loader = DataLoader(
|
| 183 |
+
dataset=test_dataset,
|
| 184 |
+
batch_size=1,
|
| 185 |
+
sampler=test_sampler,
|
| 186 |
+
num_workers=args.num_cores,
|
| 187 |
+
collate_fn=lambda _batch: _batch[0],
|
| 188 |
+
pin_memory=True
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
multiplier = multipliers[ckpt_i]
|
| 192 |
+
all_predictions = get_predictions(
|
| 193 |
+
args, model, vocab_tokens, test_loader, device, start, multiplier)
|
| 194 |
+
|
| 195 |
+
if args.local_rank > 0:
|
| 196 |
+
continue
|
| 197 |
+
|
| 198 |
+
# saving prediction results
|
| 199 |
+
with open(result_file, "w") as of:
|
| 200 |
+
of.writelines(all_predictions)
|
| 201 |
+
|
| 202 |
+
if args.do_score:
|
| 203 |
+
if os.path.exists(result_stat_file) and False:
|
| 204 |
+
log_rank_0(f"Result stat file found at {result_stat_file}, skipping scoring.")
|
| 205 |
+
continue
|
| 206 |
+
|
| 207 |
+
invalid = 0
|
| 208 |
+
accuracies = np.zeros([total, args.n_best], dtype=np.float32)
|
| 209 |
+
|
| 210 |
+
with open(result_file, "r") as f_predict:
|
| 211 |
+
for i, (smi_tgt, line_predict) in enumerate(zip(smis_tgt, f_predict)):
|
| 212 |
+
if smi_tgt == "CC": # problematic SMILES
|
| 213 |
+
continue
|
| 214 |
+
|
| 215 |
+
line_predict = "".join(line_predict.split())
|
| 216 |
+
smis_predict = line_predict.split(",")
|
| 217 |
+
smis_predict = [smi.split("_")[0] for smi in smis_predict]
|
| 218 |
+
smis_predict = [canonicalize_smiles(smi, trim=False, suppress_warning=True) for smi in smis_predict]
|
| 219 |
+
if not smis_predict[0]:
|
| 220 |
+
invalid += 1
|
| 221 |
+
smis_predict = [smi for smi in smis_predict if smi and not smi == "CC"]
|
| 222 |
+
smis_predict = list(dict.fromkeys(smis_predict))
|
| 223 |
+
|
| 224 |
+
for j, smi in enumerate(smis_predict[:args.n_best]):
|
| 225 |
+
if smi == smi_tgt:
|
| 226 |
+
accuracies[i, j:] = 1.0
|
| 227 |
+
break
|
| 228 |
+
|
| 229 |
+
with open(result_stat_file, "w") as of:
|
| 230 |
+
line = f"Total: {total}, top 1 invalid: {invalid / total * 100: .2f} %"
|
| 231 |
+
log_rank_0(line)
|
| 232 |
+
of.write(f"{line}\n")
|
| 233 |
+
|
| 234 |
+
mean_accuracies = np.mean(accuracies, axis=0)
|
| 235 |
+
for n in range(args.n_best):
|
| 236 |
+
line = f"Top {n+1} accuracy: {mean_accuracies[n] * 100: .2f} %"
|
| 237 |
+
log_rank_0(line)
|
| 238 |
+
of.write(f"{line}\n")
|
| 239 |
+
|
| 240 |
+
log_rank_0(f"Elapsed time: {time.time() - start: .2f} s")
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
if __name__ == "__main__":
|
| 244 |
+
# initialization ---------------------------------- args, logs and devices
|
| 245 |
+
predict_parser = get_predict_parser()
|
| 246 |
+
args = predict_parser.parse_args()
|
| 247 |
+
|
| 248 |
+
setup_logger(args, warning_off=True)
|
| 249 |
+
np.set_printoptions(threshold=sys.maxsize)
|
| 250 |
+
torch.set_printoptions(profile="full")
|
| 251 |
+
|
| 252 |
+
set_seed(args.seed)
|
| 253 |
+
|
| 254 |
+
main(args)
|
checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/graph2smiles_runtime/train.py
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import datetime
|
| 3 |
+
import logging
|
| 4 |
+
import numpy as np
|
| 5 |
+
import os
|
| 6 |
+
import sys
|
| 7 |
+
import torch
|
| 8 |
+
import torch.distributed as dist
|
| 9 |
+
import torch.nn as nn
|
| 10 |
+
import torch.optim as optim
|
| 11 |
+
from models.graph2smiles import Graph2SMILES
|
| 12 |
+
import time
|
| 13 |
+
from torch.nn.init import xavier_uniform_
|
| 14 |
+
from torch.nn.parallel import DistributedDataParallel as DDP
|
| 15 |
+
from torch.utils.data import DataLoader, RandomSampler, SequentialSampler
|
| 16 |
+
from torch.utils.data.distributed import DistributedSampler
|
| 17 |
+
from typing import Dict
|
| 18 |
+
from utils import parsing
|
| 19 |
+
from utils.data_utils import G2SDataset
|
| 20 |
+
from utils.preprocess_utils import load_vocab
|
| 21 |
+
from utils.train_utils import get_lr, grad_norm, log_rank_0, NoamLR, \
|
| 22 |
+
param_count, param_norm, set_seed, setup_logger
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def get_train_parser():
|
| 26 |
+
parser = argparse.ArgumentParser("train")
|
| 27 |
+
parsing.add_common_args(parser)
|
| 28 |
+
parsing.add_train_args(parser)
|
| 29 |
+
parsing.add_predict_args(parser)
|
| 30 |
+
|
| 31 |
+
return parser
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def init_dist(args):
|
| 35 |
+
if args.local_rank != -1:
|
| 36 |
+
dist.init_process_group(backend=args.backend,
|
| 37 |
+
init_method='env://',
|
| 38 |
+
timeout=datetime.timedelta(0, 7200))
|
| 39 |
+
torch.cuda.set_device(args.local_rank)
|
| 40 |
+
torch.backends.cudnn.benchmark = False
|
| 41 |
+
|
| 42 |
+
if dist.is_initialized():
|
| 43 |
+
logging.info(f"Device rank: {dist.get_rank()}")
|
| 44 |
+
sys.stdout.flush()
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def get_model(args, model_class, vocab: Dict[str, int], device):
|
| 48 |
+
state = {}
|
| 49 |
+
if args.load_from:
|
| 50 |
+
log_rank_0(f"Loading pretrained state from {args.load_from}")
|
| 51 |
+
state = torch.load(args.load_from, map_location=torch.device("cpu"))
|
| 52 |
+
pretrain_args = state["args"]
|
| 53 |
+
pretrain_args.local_rank = args.local_rank
|
| 54 |
+
parsing.log_args(pretrain_args, phase="pretraining")
|
| 55 |
+
|
| 56 |
+
model = model_class(pretrain_args, vocab)
|
| 57 |
+
pretrain_state_dict = state["state_dict"]
|
| 58 |
+
pretrain_state_dict = {k.replace("module.", ""): v for k, v in pretrain_state_dict.items()}
|
| 59 |
+
model.load_state_dict(pretrain_state_dict)
|
| 60 |
+
log_rank_0("Loaded pretrained model state_dict.")
|
| 61 |
+
else:
|
| 62 |
+
model = model_class(args, vocab)
|
| 63 |
+
for p in model.parameters():
|
| 64 |
+
if p.dim() > 1 and p.requires_grad:
|
| 65 |
+
xavier_uniform_(p)
|
| 66 |
+
|
| 67 |
+
model.to(device)
|
| 68 |
+
if args.local_rank != -1:
|
| 69 |
+
model = DDP(
|
| 70 |
+
model,
|
| 71 |
+
device_ids=[args.local_rank],
|
| 72 |
+
output_device=args.local_rank
|
| 73 |
+
)
|
| 74 |
+
log_rank_0("DDP setup finished")
|
| 75 |
+
|
| 76 |
+
return model, state
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def get_optimizer_and_scheduler(args, model, state):
|
| 80 |
+
optimizer = optim.AdamW(
|
| 81 |
+
model.parameters(),
|
| 82 |
+
lr=args.lr,
|
| 83 |
+
betas=(args.beta1, args.beta2),
|
| 84 |
+
eps=args.eps,
|
| 85 |
+
weight_decay=args.weight_decay
|
| 86 |
+
)
|
| 87 |
+
scheduler = NoamLR(
|
| 88 |
+
optimizer,
|
| 89 |
+
model_size=args.decoder_hidden_size,
|
| 90 |
+
warmup_steps=args.warmup_steps
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
if state and args.resume:
|
| 94 |
+
optimizer.load_state_dict(state["optimizer"])
|
| 95 |
+
scheduler.load_state_dict(state["scheduler"])
|
| 96 |
+
log_rank_0("Loaded pretrained optimizer and scheduler state_dicts.")
|
| 97 |
+
|
| 98 |
+
return optimizer, scheduler
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def init_loader(args, dataset, batch_size: int, bucket_size: int = 1000,
|
| 102 |
+
shuffle: bool = False, epoch: int = None):
|
| 103 |
+
dataset.sort()
|
| 104 |
+
dataset.shuffle_in_bucket(bucket_size=bucket_size)
|
| 105 |
+
dataset.batch(
|
| 106 |
+
batch_type=args.batch_type,
|
| 107 |
+
batch_size=batch_size
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
if args.local_rank != -1:
|
| 111 |
+
sampler = DistributedSampler(dataset, shuffle=shuffle)
|
| 112 |
+
if epoch is not None:
|
| 113 |
+
sampler.set_epoch(epoch)
|
| 114 |
+
else:
|
| 115 |
+
sampler = RandomSampler(dataset) if shuffle else SequentialSampler(dataset)
|
| 116 |
+
|
| 117 |
+
loader = DataLoader(
|
| 118 |
+
dataset=dataset,
|
| 119 |
+
batch_size=1,
|
| 120 |
+
sampler=sampler,
|
| 121 |
+
num_workers=args.num_cores,
|
| 122 |
+
collate_fn=lambda _batch: _batch[0],
|
| 123 |
+
pin_memory=True
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
return loader
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def _optimize(args, model, optimizer, scheduler, accum_count):
|
| 130 |
+
# for param in model.parameters():
|
| 131 |
+
# param.grad /= accum_count
|
| 132 |
+
|
| 133 |
+
nn.utils.clip_grad_norm_(model.parameters(), args.clip_norm)
|
| 134 |
+
optimizer.step()
|
| 135 |
+
scheduler.step()
|
| 136 |
+
g_norm = grad_norm(model)
|
| 137 |
+
model.zero_grad(set_to_none=True)
|
| 138 |
+
|
| 139 |
+
return g_norm
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def train_main(args):
|
| 143 |
+
args.device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
| 144 |
+
device = args.device
|
| 145 |
+
|
| 146 |
+
init_dist(args)
|
| 147 |
+
parsing.log_args(args, phase="training")
|
| 148 |
+
|
| 149 |
+
vocab_file = os.path.join(args.processed_data_path, "vocab.txt")
|
| 150 |
+
if not os.path.exists(vocab_file):
|
| 151 |
+
raise ValueError(f"Vocab file {vocab_file} not found!")
|
| 152 |
+
vocab = load_vocab(args)
|
| 153 |
+
|
| 154 |
+
os.makedirs(args.model_path, exist_ok=True)
|
| 155 |
+
model_class = Graph2SMILES
|
| 156 |
+
dataset_class = G2SDataset
|
| 157 |
+
assert args.compute_graph_distance
|
| 158 |
+
|
| 159 |
+
model, state = get_model(args, model_class, vocab, device)
|
| 160 |
+
log_rank_0(model)
|
| 161 |
+
log_rank_0(f"Number of parameters = {param_count(model)}")
|
| 162 |
+
|
| 163 |
+
optimizer, scheduler = get_optimizer_and_scheduler(args, model, state)
|
| 164 |
+
|
| 165 |
+
train_bin = os.path.join(args.processed_data_path, "train.npz")
|
| 166 |
+
val_bin = os.path.join(args.processed_data_path, "val.npz")
|
| 167 |
+
|
| 168 |
+
train_dataset = dataset_class(args, file=train_bin)
|
| 169 |
+
val_dataset = dataset_class(args, file=val_bin)
|
| 170 |
+
|
| 171 |
+
total_step = state["total_step"] if state else 0
|
| 172 |
+
accum = 0
|
| 173 |
+
g_norm = 0
|
| 174 |
+
losses, accs, ems = [], [], []
|
| 175 |
+
o_start = time.time()
|
| 176 |
+
log_rank_0("Start training")
|
| 177 |
+
|
| 178 |
+
for epoch in range(args.epoch):
|
| 179 |
+
model.train()
|
| 180 |
+
model.zero_grad(set_to_none=True)
|
| 181 |
+
train_loader = init_loader(args, train_dataset,
|
| 182 |
+
batch_size=args.train_batch_size,
|
| 183 |
+
shuffle=True,
|
| 184 |
+
epoch=epoch)
|
| 185 |
+
for batch_idx, train_batch in enumerate(train_loader):
|
| 186 |
+
|
| 187 |
+
if train_batch is None:
|
| 188 |
+
log_rank_0("Fail distance compute, too large due to node size")
|
| 189 |
+
continue
|
| 190 |
+
|
| 191 |
+
if total_step > args.max_steps:
|
| 192 |
+
log_rank_0("Max steps reached, finish training")
|
| 193 |
+
exit(0)
|
| 194 |
+
train_batch.to(device)
|
| 195 |
+
batch_losses, acc, em = model(train_batch)
|
| 196 |
+
loss = batch_losses.mean()
|
| 197 |
+
(loss / args.accumulation_count).backward() # average out the loss over multiple batches during accumulation
|
| 198 |
+
losses.append(loss.item())
|
| 199 |
+
accs.append(acc.item() * 100)
|
| 200 |
+
ems.append(em.item() * 100)
|
| 201 |
+
|
| 202 |
+
accum += 1
|
| 203 |
+
if accum == args.accumulation_count:
|
| 204 |
+
g_norm = _optimize(args, model, optimizer, scheduler, args.accumulation_count)
|
| 205 |
+
accum = 0
|
| 206 |
+
total_step += 1
|
| 207 |
+
|
| 208 |
+
if (accum == 0) and (total_step > 0) and (total_step % args.log_iter == 0):
|
| 209 |
+
log_rank_0(f"Step {total_step}, loss: {np.mean(losses)}, "
|
| 210 |
+
f"acc: {np.mean(accs): .4f}, em: {np.mean(ems): .4f}, "
|
| 211 |
+
f"p_norm: {param_norm(model): .4f}, g_norm: {g_norm: .4f}, "
|
| 212 |
+
f"lr: {get_lr(optimizer): .6f}, "
|
| 213 |
+
f"elapsed time: {time.time() - o_start: .0f}")
|
| 214 |
+
losses, accs, ems = [], [], []
|
| 215 |
+
|
| 216 |
+
if (accum == 0) and (total_step > 0) and (total_step % args.eval_iter == 0):
|
| 217 |
+
model.eval()
|
| 218 |
+
val_count = 100
|
| 219 |
+
val_losses, val_accs, val_ems = [], [], []
|
| 220 |
+
|
| 221 |
+
val_loader = init_loader(args, val_dataset,
|
| 222 |
+
batch_size=args.val_batch_size,
|
| 223 |
+
shuffle=True,
|
| 224 |
+
epoch=None)
|
| 225 |
+
with torch.no_grad():
|
| 226 |
+
for val_idx, val_batch in enumerate(val_loader):
|
| 227 |
+
if val_batch is None:
|
| 228 |
+
log_rank_0("Fail distance compute, too large due to node size")
|
| 229 |
+
continue
|
| 230 |
+
|
| 231 |
+
if val_idx >= val_count:
|
| 232 |
+
break
|
| 233 |
+
val_batch.to(device)
|
| 234 |
+
val_batch_losses, val_acc, val_em = model(val_batch)
|
| 235 |
+
val_loss = val_batch_losses.mean()
|
| 236 |
+
val_losses.append(val_loss.item())
|
| 237 |
+
val_accs.append(val_acc.item() * 100)
|
| 238 |
+
val_ems.append(val_em.item() * 100)
|
| 239 |
+
|
| 240 |
+
log_rank_0(f"Validation (with teacher) at step {total_step}, "
|
| 241 |
+
f"val loss: {np.mean(val_losses)}, "
|
| 242 |
+
f"val acc: {np.mean(val_accs): .4f}, "
|
| 243 |
+
f"val em: {np.mean(val_ems): .4f}")
|
| 244 |
+
model.train()
|
| 245 |
+
|
| 246 |
+
# Important: saving only at one node or the ckpt would be corrupted!
|
| 247 |
+
if dist.is_initialized() and dist.get_rank() > 0:
|
| 248 |
+
continue
|
| 249 |
+
|
| 250 |
+
if (accum == 0) and (total_step > 0) and (total_step % args.save_iter == 0):
|
| 251 |
+
n_iter = total_step // args.save_iter - 1
|
| 252 |
+
log_rank_0(f"Saving at step {total_step}")
|
| 253 |
+
state = {
|
| 254 |
+
"args": args,
|
| 255 |
+
"total_step": total_step,
|
| 256 |
+
"state_dict": model.state_dict(),
|
| 257 |
+
"optimizer": optimizer.state_dict(),
|
| 258 |
+
"scheduler": scheduler.state_dict()
|
| 259 |
+
}
|
| 260 |
+
torch.save(state, os.path.join(args.model_path, f"model.{total_step}_{n_iter}.pt"))
|
| 261 |
+
|
| 262 |
+
# lastly
|
| 263 |
+
if (args.accumulation_count > 1) and (accum > 0):
|
| 264 |
+
g_norm = _optimize(args, model, optimizer, scheduler, args.accumulation_count)
|
| 265 |
+
accum = 0
|
| 266 |
+
# total_step += 1 # for partial batch, do not increase total_step
|
| 267 |
+
|
| 268 |
+
if args.local_rank != -1:
|
| 269 |
+
dist.barrier()
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
if __name__ == "__main__":
|
| 273 |
+
train_parser = get_train_parser()
|
| 274 |
+
args = train_parser.parse_args()
|
| 275 |
+
|
| 276 |
+
# set random seed
|
| 277 |
+
set_seed(args.seed)
|
| 278 |
+
|
| 279 |
+
# logger setup
|
| 280 |
+
logger = setup_logger(args)
|
| 281 |
+
|
| 282 |
+
# maximize display for debugging
|
| 283 |
+
np.set_printoptions(threshold=sys.maxsize)
|
| 284 |
+
torch.set_printoptions(profile="full")
|
| 285 |
+
|
| 286 |
+
args.local_rank = int(os.environ["LOCAL_RANK"]) if os.environ.get("LOCAL_RANK") else -1
|
| 287 |
+
train_main(args)
|
checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/graph2smiles_runtime/utils/c_calculate.so
ADDED
|
Binary file (7.92 kB). View file
|
|
|
checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/graph2smiles_runtime/utils/chem_utils.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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'Co', 'Se', 'Ti',
|
| 8 |
+
'Zn', 'H', 'Li', 'Ge', 'Cu', 'Au', 'Ni', 'Cd', 'In', 'Mn', 'Zr', 'Cr', 'Pt', 'Hg', 'Pb',
|
| 9 |
+
'W', 'Ru', 'Nb', 'Re', 'Te', 'Rh', 'Ta', 'Tc', 'Ba', 'Bi', 'Hf', 'Mo', 'U', 'Sm', 'Os', 'Ir',
|
| 10 |
+
'Ce', 'Gd', 'Ga', 'Cs', '*', 'unk']
|
| 11 |
+
ATOM_DICT = {symbol: i for i, symbol in enumerate(ATOM_LIST)}
|
| 12 |
+
|
| 13 |
+
MAX_NB = 10
|
| 14 |
+
DEGREES = list(range(MAX_NB))
|
| 15 |
+
HYBRIDIZATION = [Chem.rdchem.HybridizationType.SP,
|
| 16 |
+
Chem.rdchem.HybridizationType.SP2,
|
| 17 |
+
Chem.rdchem.HybridizationType.SP3,
|
| 18 |
+
Chem.rdchem.HybridizationType.SP3D,
|
| 19 |
+
Chem.rdchem.HybridizationType.SP3D2]
|
| 20 |
+
HYBRIDIZATION_DICT = {hb: i for i, hb in enumerate(HYBRIDIZATION)}
|
| 21 |
+
|
| 22 |
+
FORMAL_CHARGE = [-1, -2, 1, 2, 0]
|
| 23 |
+
FC_DICT = {fc: i for i, fc in enumerate(FORMAL_CHARGE)}
|
| 24 |
+
|
| 25 |
+
VALENCE = [0, 1, 2, 3, 4, 5, 6]
|
| 26 |
+
VALENCE_DICT = {vl: i for i, vl in enumerate(VALENCE)}
|
| 27 |
+
|
| 28 |
+
NUM_Hs = [0, 1, 2, 3, 4]
|
| 29 |
+
NUM_Hs_DICT = {nH: i for i, nH in enumerate(NUM_Hs)}
|
| 30 |
+
|
| 31 |
+
CHIRAL_TAG = [Chem.rdchem.ChiralType.CHI_TETRAHEDRAL_CW,
|
| 32 |
+
Chem.rdchem.ChiralType.CHI_TETRAHEDRAL_CCW,
|
| 33 |
+
Chem.rdchem.ChiralType.CHI_UNSPECIFIED]
|
| 34 |
+
CHIRAL_TAG_DICT = {ct: i for i, ct in enumerate(CHIRAL_TAG)}
|
| 35 |
+
|
| 36 |
+
RS_TAG = ["R", "S", "None"]
|
| 37 |
+
RS_TAG_DICT = {rs: i for i, rs in enumerate(RS_TAG)}
|
| 38 |
+
|
| 39 |
+
BOND_TYPES = [None,
|
| 40 |
+
Chem.rdchem.BondType.SINGLE,
|
| 41 |
+
Chem.rdchem.BondType.DOUBLE,
|
| 42 |
+
Chem.rdchem.BondType.TRIPLE,
|
| 43 |
+
Chem.rdchem.BondType.AROMATIC]
|
| 44 |
+
BOND_TYPES_DICT = {bt: i for i, bt in enumerate(BOND_TYPES)}
|
| 45 |
+
|
| 46 |
+
BOND_FLOAT_TO_TYPE = {
|
| 47 |
+
0.0: BOND_TYPES[0],
|
| 48 |
+
1.0: BOND_TYPES[1],
|
| 49 |
+
2.0: BOND_TYPES[2],
|
| 50 |
+
3.0: BOND_TYPES[3],
|
| 51 |
+
1.5: BOND_TYPES[4],
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
BOND_STEREO = [Chem.rdchem.BondStereo.STEREOE,
|
| 55 |
+
Chem.rdchem.BondStereo.STEREOZ,
|
| 56 |
+
Chem.rdchem.BondStereo.STEREONONE]
|
| 57 |
+
BOND_STEREO_DICT = {bs: i for i, bs in enumerate(BOND_STEREO)}
|
| 58 |
+
|
| 59 |
+
BOND_DELTAS = {-3: 0, -2: 1, -1.5: 2, -1: 3, -0.5: 4, 0: 5, 0.5: 6, 1: 7, 1.5: 8, 2: 9, 3: 10}
|
| 60 |
+
BOND_FLOATS = [0.0, 1.0, 2.0, 3.0, 1.5]
|
| 61 |
+
|
| 62 |
+
RXN_CLASSES = list(range(10))
|
| 63 |
+
|
| 64 |
+
# ATOM_FDIM = len(ATOM_LIST) + len(DEGREES) + len(FORMAL_CHARGE) + len(HYBRIDIZATION) \
|
| 65 |
+
# + len(VALENCE) + len(NUM_Hs) + 1
|
| 66 |
+
ATOM_FDIM = [len(ATOM_LIST), len(DEGREES), len(FORMAL_CHARGE), len(HYBRIDIZATION), len(VALENCE),
|
| 67 |
+
len(NUM_Hs), len(CHIRAL_TAG), len(RS_TAG), 2]
|
| 68 |
+
# BOND_FDIM = 6
|
| 69 |
+
BOND_FDIM = 9
|
| 70 |
+
BOND_FDIMS = [5, 3, 2, 2]
|
| 71 |
+
BINARY_FDIM = 5 + BOND_FDIM
|
| 72 |
+
INVALID_BOND = -1
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def get_atom_features_sparse(atom: Chem.Atom) -> List[int]:
|
| 76 |
+
"""Get atom features as sparse idx.
|
| 77 |
+
|
| 78 |
+
Parameters
|
| 79 |
+
----------
|
| 80 |
+
atom: Chem.Atom,
|
| 81 |
+
Atom object from RDKit
|
| 82 |
+
"""
|
| 83 |
+
feature_array = []
|
| 84 |
+
symbol = atom.GetSymbol()
|
| 85 |
+
symbol_id = ATOM_DICT.get(symbol, ATOM_DICT["unk"])
|
| 86 |
+
feature_array.append(symbol_id)
|
| 87 |
+
|
| 88 |
+
if symbol in ["*", "unk"]:
|
| 89 |
+
padding = [999999999] * len(ATOM_FDIM)
|
| 90 |
+
feature_array.extend(padding)
|
| 91 |
+
|
| 92 |
+
else:
|
| 93 |
+
degree_id = atom.GetDegree()
|
| 94 |
+
if degree_id not in DEGREES:
|
| 95 |
+
degree_id = 9
|
| 96 |
+
formal_charge_id = FC_DICT.get(atom.GetFormalCharge(), 4)
|
| 97 |
+
hybridization_id = HYBRIDIZATION_DICT.get(atom.GetHybridization(), 4)
|
| 98 |
+
valence_id = VALENCE_DICT.get(atom.GetTotalValence(), 6)
|
| 99 |
+
num_h_id = NUM_Hs_DICT.get(atom.GetTotalNumHs(), 0)
|
| 100 |
+
chiral_tag_id = CHIRAL_TAG_DICT.get(atom.GetChiralTag(), 2)
|
| 101 |
+
|
| 102 |
+
rs_tag = atom.GetPropsAsDict().get("_CIPCode", "None")
|
| 103 |
+
rs_tag_id = RS_TAG_DICT.get(rs_tag, 2)
|
| 104 |
+
|
| 105 |
+
is_aromatic = int(atom.GetIsAromatic())
|
| 106 |
+
feature_array.extend([degree_id, formal_charge_id, hybridization_id,
|
| 107 |
+
valence_id, num_h_id, chiral_tag_id, rs_tag_id, is_aromatic])
|
| 108 |
+
|
| 109 |
+
# legacy; for reaction class
|
| 110 |
+
feature_array.append(0)
|
| 111 |
+
|
| 112 |
+
return feature_array
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def get_bond_features(bond: Chem.Bond) -> List[int]:
|
| 116 |
+
"""Get bond features.
|
| 117 |
+
|
| 118 |
+
Parameters
|
| 119 |
+
----------
|
| 120 |
+
bond: Chem.Bond,
|
| 121 |
+
bond object
|
| 122 |
+
"""
|
| 123 |
+
bt = bond.GetBondType()
|
| 124 |
+
bond_features = [int(bt == bond_type) for bond_type in BOND_TYPES[1:]]
|
| 125 |
+
bs = bond.GetStereo()
|
| 126 |
+
bond_features.extend([int(bs == bond_stereo) for bond_stereo in BOND_STEREO])
|
| 127 |
+
bond_features.extend([int(bond.GetIsConjugated()), int(bond.IsInRing())])
|
| 128 |
+
|
| 129 |
+
return bond_features
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def get_bond_features_sparse(bond: Chem.Bond) -> List[int]:
|
| 133 |
+
"""Get bond features.
|
| 134 |
+
|
| 135 |
+
Parameters
|
| 136 |
+
----------
|
| 137 |
+
bond: Chem.Bond,
|
| 138 |
+
bond object
|
| 139 |
+
"""
|
| 140 |
+
bt = BOND_TYPES_DICT.get(bond.GetBondType(), 0)
|
| 141 |
+
bs = BOND_STEREO_DICT.get(bond.GetStereo(), 2)
|
| 142 |
+
bond_features = [bt, bs, int(bond.GetIsConjugated()), int(bond.IsInRing())]
|
| 143 |
+
|
| 144 |
+
return bond_features
|
checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/graph2smiles_runtime/utils/ctypes_calculator.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes
|
| 2 |
+
import numpy as np
|
| 3 |
+
import numpy.ctypeslib as npct
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class DistanceCalculator:
|
| 7 |
+
# Declare an alias for the C type int*, equivalent to int[]
|
| 8 |
+
array_1d_uint8 = npct.ndpointer(dtype=np.uint8, ndim=1, flags="C_CONTIGUOUS")
|
| 9 |
+
array_1d_bool = npct.ndpointer(dtype=np.bool_, ndim=1, flags="C_CONTIGUOUS")
|
| 10 |
+
|
| 11 |
+
# Load c_func.so into my_lib; my_lib.c_func is now callable
|
| 12 |
+
my_lib = npct.load_library("c_calculate", "./utils")
|
| 13 |
+
|
| 14 |
+
my_lib.c_calculate.restype = None # return type
|
| 15 |
+
my_lib.c_calculate.argtypes = [ # args type
|
| 16 |
+
array_1d_uint8, ctypes.c_int32,
|
| 17 |
+
array_1d_bool,
|
| 18 |
+
ctypes.c_int32
|
| 19 |
+
]
|
| 20 |
+
|
| 21 |
+
@staticmethod
|
| 22 |
+
def calculate(adjacency: np.ndarray,
|
| 23 |
+
a_length: int,
|
| 24 |
+
max_distance: int) -> np.ndarray:
|
| 25 |
+
flattened_distance = np.zeros(a_length * a_length, dtype=np.uint8)
|
| 26 |
+
flattened_adjacency = adjacency.ravel()
|
| 27 |
+
|
| 28 |
+
DistanceCalculator.my_lib.c_calculate(
|
| 29 |
+
flattened_distance, a_length,
|
| 30 |
+
flattened_adjacency,
|
| 31 |
+
max_distance
|
| 32 |
+
)
|
| 33 |
+
distance = flattened_distance.reshape(a_length, a_length)
|
| 34 |
+
|
| 35 |
+
return distance
|
checkpoints/askcos_retro_graph2smiles/pistachio_23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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import numpy as np
|
| 3 |
+
import os
|
| 4 |
+
import time
|
| 5 |
+
import torch
|
| 6 |
+
from rdkit import Chem
|
| 7 |
+
from torch.utils.data import Dataset
|
| 8 |
+
from typing import List, Tuple
|
| 9 |
+
from utils.chem_utils import ATOM_FDIM, BOND_FDIM, get_atom_features_sparse
|
| 10 |
+
from utils.ctypes_calculator import DistanceCalculator
|
| 11 |
+
from utils.preprocess_utils import load_vocab
|
| 12 |
+
from utils.train_utils import log_rank_0
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def len2idx(lens) -> np.ndarray:
|
| 16 |
+
end_indices = np.cumsum(lens)
|
| 17 |
+
start_indices = np.concatenate([[0], end_indices[:-1]], axis=0)
|
| 18 |
+
indices = np.stack([start_indices, end_indices], axis=1)
|
| 19 |
+
|
| 20 |
+
return indices
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def canonicalize_smiles(smiles, remove_atom_number=True, trim=True, suppress_warning=False):
|
| 24 |
+
mol = Chem.MolFromSmiles(smiles)
|
| 25 |
+
|
| 26 |
+
if mol is None:
|
| 27 |
+
cano_smiles = ""
|
| 28 |
+
|
| 29 |
+
else:
|
| 30 |
+
try:
|
| 31 |
+
if trim and mol.GetNumHeavyAtoms() < 2:
|
| 32 |
+
if not suppress_warning:
|
| 33 |
+
logging.info(f"Problematic smiles: {smiles}, setting it to 'CC'")
|
| 34 |
+
cano_smiles = "CC" # TODO: hardcode to ignore
|
| 35 |
+
else:
|
| 36 |
+
if remove_atom_number:
|
| 37 |
+
[a.ClearProp('molAtomMapNumber') for a in mol.GetAtoms()]
|
| 38 |
+
cano_smiles = Chem.MolToSmiles(mol, isomericSmiles=True)
|
| 39 |
+
except RuntimeError as e:
|
| 40 |
+
cano_smiles = ""
|
| 41 |
+
|
| 42 |
+
return cano_smiles
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class G2SBatch:
|
| 46 |
+
def __init__(self,
|
| 47 |
+
fnode: torch.Tensor,
|
| 48 |
+
fmess: torch.Tensor,
|
| 49 |
+
agraph: torch.Tensor,
|
| 50 |
+
bgraph: torch.Tensor,
|
| 51 |
+
atom_scope: List,
|
| 52 |
+
bond_scope: List,
|
| 53 |
+
tgt_token_ids: torch.Tensor,
|
| 54 |
+
tgt_lengths: torch.Tensor,
|
| 55 |
+
distances: torch.Tensor = None):
|
| 56 |
+
self.fnode = fnode
|
| 57 |
+
self.fmess = fmess
|
| 58 |
+
self.agraph = agraph
|
| 59 |
+
self.bgraph = bgraph
|
| 60 |
+
self.atom_scope = atom_scope
|
| 61 |
+
self.bond_scope = bond_scope
|
| 62 |
+
self.tgt_token_ids = tgt_token_ids
|
| 63 |
+
self.tgt_lengths = tgt_lengths
|
| 64 |
+
self.distances = distances
|
| 65 |
+
|
| 66 |
+
self.size = len(tgt_lengths)
|
| 67 |
+
|
| 68 |
+
def to(self, device):
|
| 69 |
+
self.fnode = self.fnode.to(device)
|
| 70 |
+
self.fmess = self.fmess.to(device)
|
| 71 |
+
self.agraph = self.agraph.to(device)
|
| 72 |
+
self.bgraph = self.bgraph.to(device)
|
| 73 |
+
self.tgt_token_ids = self.tgt_token_ids.to(device)
|
| 74 |
+
self.tgt_lengths = self.tgt_lengths.to(device)
|
| 75 |
+
|
| 76 |
+
if self.distances is not None:
|
| 77 |
+
self.distances = self.distances.to(device)
|
| 78 |
+
|
| 79 |
+
def pin_memory(self):
|
| 80 |
+
self.fnode = self.fnode.pin_memory()
|
| 81 |
+
self.fmess = self.fmess.pin_memory()
|
| 82 |
+
self.agraph = self.agraph.pin_memory()
|
| 83 |
+
self.bgraph = self.bgraph.pin_memory()
|
| 84 |
+
self.tgt_token_ids = self.tgt_token_ids.pin_memory()
|
| 85 |
+
self.tgt_lengths = self.tgt_lengths.pin_memory()
|
| 86 |
+
|
| 87 |
+
if self.distances is not None:
|
| 88 |
+
self.distances = self.distances.pin_memory()
|
| 89 |
+
|
| 90 |
+
return self
|
| 91 |
+
|
| 92 |
+
def log_tensor_shape(self):
|
| 93 |
+
log_rank_0(f"fnode: {self.fnode.shape}, "
|
| 94 |
+
f"fmess: {self.fmess.shape}, "
|
| 95 |
+
f"tgt_token_ids: {self.tgt_token_ids.shape}, "
|
| 96 |
+
f"tgt_lengths: {self.tgt_lengths}")
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
class G2SDataset(Dataset):
|
| 100 |
+
def __init__(self, args, file: str):
|
| 101 |
+
self.args = args
|
| 102 |
+
|
| 103 |
+
self.a_scopes = []
|
| 104 |
+
self.b_scopes = []
|
| 105 |
+
self.a_features = []
|
| 106 |
+
self.b_features = []
|
| 107 |
+
self.a_graphs = []
|
| 108 |
+
self.b_graphs = []
|
| 109 |
+
self.a_scopes_lens = []
|
| 110 |
+
self.b_scopes_lens = []
|
| 111 |
+
self.a_features_lens = []
|
| 112 |
+
self.b_features_lens = []
|
| 113 |
+
|
| 114 |
+
self.src_token_ids = [] # loaded but not batched
|
| 115 |
+
self.src_lens = []
|
| 116 |
+
self.tgt_token_ids = []
|
| 117 |
+
self.tgt_lens = []
|
| 118 |
+
|
| 119 |
+
self.data_indices = []
|
| 120 |
+
self.batch_sizes = []
|
| 121 |
+
self.batch_starts = []
|
| 122 |
+
self.batch_ends = []
|
| 123 |
+
|
| 124 |
+
self.vocab = load_vocab(args)
|
| 125 |
+
self.vocab_tokens = [k for k, v in sorted(self.vocab.items(), key=lambda tup: tup[1])]
|
| 126 |
+
|
| 127 |
+
log_rank_0(f"Loading preprocessed features from {file}")
|
| 128 |
+
feat = np.load(file)
|
| 129 |
+
for attr in ["a_scopes", "b_scopes", "a_features", "b_features", "a_graphs", "b_graphs",
|
| 130 |
+
"a_scopes_lens", "b_scopes_lens", "a_features_lens", "b_features_lens",
|
| 131 |
+
"src_token_ids", "src_lens", "tgt_token_ids", "tgt_lens"]:
|
| 132 |
+
setattr(self, attr, feat[attr])
|
| 133 |
+
|
| 134 |
+
# mask out chiral tag (as UNSPECIFIED)
|
| 135 |
+
if args.mask_rel_chirality == 1:
|
| 136 |
+
self.a_features[:, 6] = 2
|
| 137 |
+
|
| 138 |
+
assert len(self.a_scopes_lens) == len(self.b_scopes_lens) == \
|
| 139 |
+
len(self.a_features_lens) == len(self.b_features_lens) == \
|
| 140 |
+
len(self.src_token_ids) == len(self.src_lens) == \
|
| 141 |
+
len(self.tgt_token_ids) == len(self.tgt_lens), \
|
| 142 |
+
f"Lengths of source and target mismatch!"
|
| 143 |
+
|
| 144 |
+
self.a_scopes_indices = len2idx(self.a_scopes_lens)
|
| 145 |
+
self.b_scopes_indices = len2idx(self.b_scopes_lens)
|
| 146 |
+
self.a_features_indices = len2idx(self.a_features_lens)
|
| 147 |
+
self.b_features_indices = len2idx(self.b_features_lens)
|
| 148 |
+
|
| 149 |
+
del self.a_scopes_lens, self.b_scopes_lens, self.a_features_lens, self.b_features_lens
|
| 150 |
+
|
| 151 |
+
self.data_size = len(self.src_token_ids)
|
| 152 |
+
self.data_indices = np.arange(self.data_size)
|
| 153 |
+
|
| 154 |
+
self.distance_calculator = None
|
| 155 |
+
if self.args.compute_graph_distance:
|
| 156 |
+
self.distance_calculator = DistanceCalculator()
|
| 157 |
+
|
| 158 |
+
log_rank_0(f"Loaded and initialized G2SDataset, size: {self.data_size}")
|
| 159 |
+
|
| 160 |
+
def sort(self):
|
| 161 |
+
if self.args.verbose:
|
| 162 |
+
start = time.time()
|
| 163 |
+
log_rank_0("Calling G2SDataset.sort()")
|
| 164 |
+
self.data_indices = np.argsort(self.src_lens)
|
| 165 |
+
log_rank_0(f"Done, time: {time.time() - start: .2f} s")
|
| 166 |
+
else:
|
| 167 |
+
self.data_indices = np.argsort(self.src_lens)
|
| 168 |
+
|
| 169 |
+
def shuffle_in_bucket(self, bucket_size: int):
|
| 170 |
+
if self.args.verbose:
|
| 171 |
+
start = time.time()
|
| 172 |
+
log_rank_0("Calling G2SDataset.shuffle_in_bucket()")
|
| 173 |
+
for i in range(0, self.data_size, bucket_size):
|
| 174 |
+
np.random.shuffle(self.data_indices[i:i+bucket_size])
|
| 175 |
+
log_rank_0(f"Done, time: {time.time() - start: .2f} s")
|
| 176 |
+
else:
|
| 177 |
+
for i in range(0, self.data_size, bucket_size):
|
| 178 |
+
np.random.shuffle(self.data_indices[i:i + bucket_size])
|
| 179 |
+
|
| 180 |
+
def batch(self, batch_type: str, batch_size: int):
|
| 181 |
+
start = time.time()
|
| 182 |
+
log_rank_0("Calling G2SDataset.batch()")
|
| 183 |
+
|
| 184 |
+
self.batch_sizes = []
|
| 185 |
+
if batch_type in ["samples", "atoms"]:
|
| 186 |
+
raise NotImplementedError
|
| 187 |
+
|
| 188 |
+
elif batch_type.startswith("tokens"):
|
| 189 |
+
sample_size = 0
|
| 190 |
+
max_batch_src_len = 0
|
| 191 |
+
max_batch_tgt_len = 0
|
| 192 |
+
|
| 193 |
+
for data_idx in self.data_indices:
|
| 194 |
+
src_len = self.src_lens[data_idx]
|
| 195 |
+
tgt_len = self.tgt_lens[data_idx]
|
| 196 |
+
|
| 197 |
+
max_batch_src_len = max(src_len, max_batch_src_len)
|
| 198 |
+
max_batch_tgt_len = max(tgt_len, max_batch_tgt_len)
|
| 199 |
+
while self.args.enable_amp and not max_batch_src_len % 8 == 0: # for amp
|
| 200 |
+
max_batch_src_len += 1
|
| 201 |
+
while self.args.enable_amp and not max_batch_tgt_len % 8 == 0: # for amp
|
| 202 |
+
max_batch_tgt_len += 1
|
| 203 |
+
|
| 204 |
+
if batch_type == "tokens" and \
|
| 205 |
+
max_batch_src_len * (sample_size + 1) <= batch_size:
|
| 206 |
+
sample_size += 1
|
| 207 |
+
elif batch_type == "tokens_sum" and \
|
| 208 |
+
(max_batch_src_len + max_batch_tgt_len) * (sample_size + 1) <= batch_size:
|
| 209 |
+
sample_size += 1
|
| 210 |
+
elif self.args.enable_amp and not sample_size % 8 == 0:
|
| 211 |
+
sample_size += 1
|
| 212 |
+
else:
|
| 213 |
+
self.batch_sizes.append(sample_size)
|
| 214 |
+
|
| 215 |
+
sample_size = 1
|
| 216 |
+
max_batch_src_len = src_len
|
| 217 |
+
max_batch_tgt_len = tgt_len
|
| 218 |
+
while self.args.enable_amp and not max_batch_src_len % 8 == 0: # for amp
|
| 219 |
+
max_batch_src_len += 1
|
| 220 |
+
while self.args.enable_amp and not max_batch_tgt_len % 8 == 0: # for amp
|
| 221 |
+
max_batch_tgt_len += 1
|
| 222 |
+
|
| 223 |
+
# lastly
|
| 224 |
+
self.batch_sizes.append(sample_size)
|
| 225 |
+
self.batch_sizes = np.array(self.batch_sizes)
|
| 226 |
+
assert np.sum(self.batch_sizes) == self.data_size, \
|
| 227 |
+
f"Size mismatch! Data size: {self.data_size}, sum batch sizes: {np.sum(self.batch_sizes)}"
|
| 228 |
+
|
| 229 |
+
self.batch_ends = np.cumsum(self.batch_sizes)
|
| 230 |
+
self.batch_starts = np.concatenate([[0], self.batch_ends[:-1]])
|
| 231 |
+
|
| 232 |
+
else:
|
| 233 |
+
raise ValueError(f"batch_type {batch_type} not supported!")
|
| 234 |
+
|
| 235 |
+
log_rank_0(f"Done, time: {time.time() - start: .2f} s, total batches: {self.__len__()}")
|
| 236 |
+
|
| 237 |
+
def __getitem__(self, index: int) -> G2SBatch:
|
| 238 |
+
batch_index = index
|
| 239 |
+
batch_start = self.batch_starts[batch_index]
|
| 240 |
+
batch_end = self.batch_ends[batch_index]
|
| 241 |
+
|
| 242 |
+
data_indices = self.data_indices[batch_start:batch_end]
|
| 243 |
+
|
| 244 |
+
# collating, essentially
|
| 245 |
+
# source (graph)
|
| 246 |
+
graph_features = []
|
| 247 |
+
a_lengths = []
|
| 248 |
+
|
| 249 |
+
# ------
|
| 250 |
+
modified_data_indicies = []
|
| 251 |
+
for data_index in data_indices:
|
| 252 |
+
start, end = self.a_scopes_indices[data_index]
|
| 253 |
+
a_scope = self.a_scopes[start:end]
|
| 254 |
+
a_length = a_scope[-1][0] + a_scope[-1][1] - a_scope[0][0]
|
| 255 |
+
if a_length <= 600: modified_data_indicies.append(data_index) # hard cap on number of atoms for distance calculation
|
| 256 |
+
# if a_length <= 200: modified_data_indicies.append(data_index) # hard cap on number of atoms for distance calculation
|
| 257 |
+
# else: log_rank_0("Node length was {}".format(a_length))
|
| 258 |
+
|
| 259 |
+
if not modified_data_indicies: return
|
| 260 |
+
modified_data_indicies.extend([min(modified_data_indicies)]*(len(data_indices)-len(modified_data_indicies))) # duplicate till full
|
| 261 |
+
assert len(modified_data_indicies) == len(data_indices)
|
| 262 |
+
# ------
|
| 263 |
+
|
| 264 |
+
# for data_index in data_indices:
|
| 265 |
+
for data_index in modified_data_indicies:
|
| 266 |
+
start, end = self.a_scopes_indices[data_index]
|
| 267 |
+
a_scope = self.a_scopes[start:end]
|
| 268 |
+
a_length = a_scope[-1][0] + a_scope[-1][1] - a_scope[0][0]
|
| 269 |
+
|
| 270 |
+
start, end = self.b_scopes_indices[data_index]
|
| 271 |
+
b_scope = self.b_scopes[start:end]
|
| 272 |
+
|
| 273 |
+
start, end = self.a_features_indices[data_index]
|
| 274 |
+
a_feature = self.a_features[start:end]
|
| 275 |
+
a_graph = self.a_graphs[start:end]
|
| 276 |
+
|
| 277 |
+
start, end = self.b_features_indices[data_index]
|
| 278 |
+
b_feature = self.b_features[start:end]
|
| 279 |
+
b_graph = self.b_graphs[start:end]
|
| 280 |
+
|
| 281 |
+
graph_feature = (a_scope, b_scope, a_feature, b_feature, a_graph, b_graph)
|
| 282 |
+
graph_features.append(graph_feature)
|
| 283 |
+
a_lengths.append(a_length)
|
| 284 |
+
|
| 285 |
+
# # collating, essentially
|
| 286 |
+
# # source (graph)
|
| 287 |
+
# graph_features = []
|
| 288 |
+
# a_lengths = []
|
| 289 |
+
# for data_index in data_indices:
|
| 290 |
+
# start, end = self.a_scopes_indices[data_index]
|
| 291 |
+
# a_scope = self.a_scopes[start:end]
|
| 292 |
+
# a_length = a_scope[-1][0] + a_scope[-1][1] - a_scope[0][0]
|
| 293 |
+
|
| 294 |
+
# start, end = self.b_scopes_indices[data_index]
|
| 295 |
+
# b_scope = self.b_scopes[start:end]
|
| 296 |
+
|
| 297 |
+
# start, end = self.a_features_indices[data_index]
|
| 298 |
+
# a_feature = self.a_features[start:end]
|
| 299 |
+
# a_graph = self.a_graphs[start:end]
|
| 300 |
+
|
| 301 |
+
# start, end = self.b_features_indices[data_index]
|
| 302 |
+
# b_feature = self.b_features[start:end]
|
| 303 |
+
# b_graph = self.b_graphs[start:end]
|
| 304 |
+
|
| 305 |
+
# graph_feature = (a_scope, b_scope, a_feature, b_feature, a_graph, b_graph)
|
| 306 |
+
# graph_features.append(graph_feature)
|
| 307 |
+
# a_lengths.append(a_length)
|
| 308 |
+
|
| 309 |
+
fnode, fmess, agraph, bgraph, atom_scope, bond_scope = collate_graph_features(graph_features)
|
| 310 |
+
|
| 311 |
+
# target (seq)
|
| 312 |
+
tgt_token_ids = self.tgt_token_ids[data_indices]
|
| 313 |
+
tgt_lengths = self.tgt_lens[data_indices]
|
| 314 |
+
|
| 315 |
+
tgt_token_ids = tgt_token_ids[:, :max(tgt_lengths)]
|
| 316 |
+
|
| 317 |
+
tgt_token_ids = torch.as_tensor(tgt_token_ids, dtype=torch.long)
|
| 318 |
+
tgt_lengths = torch.tensor(tgt_lengths, dtype=torch.long)
|
| 319 |
+
|
| 320 |
+
distances = None
|
| 321 |
+
if self.args.compute_graph_distance:
|
| 322 |
+
distances = collate_graph_distances(self.args, graph_features, a_lengths, self.distance_calculator)
|
| 323 |
+
|
| 324 |
+
"""
|
| 325 |
+
logging.info("--------------------src_tokens--------------------")
|
| 326 |
+
for data_index in data_indices:
|
| 327 |
+
smi = "".join(self.vocab_tokens[src_token_id] for src_token_id in self.src_token_ids[data_index])
|
| 328 |
+
logging.info(smi)
|
| 329 |
+
logging.info("--------------------distances--------------------")
|
| 330 |
+
logging.info(f"{distances}")
|
| 331 |
+
exit(0)
|
| 332 |
+
"""
|
| 333 |
+
|
| 334 |
+
g2s_batch = G2SBatch(
|
| 335 |
+
fnode=fnode,
|
| 336 |
+
fmess=fmess,
|
| 337 |
+
agraph=agraph,
|
| 338 |
+
bgraph=bgraph,
|
| 339 |
+
atom_scope=atom_scope,
|
| 340 |
+
bond_scope=bond_scope,
|
| 341 |
+
tgt_token_ids=tgt_token_ids,
|
| 342 |
+
tgt_lengths=tgt_lengths,
|
| 343 |
+
distances=distances
|
| 344 |
+
)
|
| 345 |
+
# g2s_batch.log_tensor_shape()
|
| 346 |
+
|
| 347 |
+
return g2s_batch
|
| 348 |
+
|
| 349 |
+
def __len__(self):
|
| 350 |
+
return len(self.batch_sizes)
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
def collate_graph_features(graph_features: List[Tuple], directed: bool = True
|
| 354 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor,
|
| 355 |
+
List[np.ndarray], List[np.ndarray]]:
|
| 356 |
+
if directed:
|
| 357 |
+
padded_features = get_atom_features_sparse(Chem.Atom("*"))
|
| 358 |
+
fnode = [np.array(padded_features)]
|
| 359 |
+
fmess = [np.zeros(shape=[1, 2 + BOND_FDIM], dtype=np.int32)]
|
| 360 |
+
agraph = [np.zeros(shape=[1, 11], dtype=np.int32)]
|
| 361 |
+
bgraph = [np.zeros(shape=[1, 11], dtype=np.int32)]
|
| 362 |
+
|
| 363 |
+
n_unique_bonds = 1
|
| 364 |
+
edge_offset = 1
|
| 365 |
+
|
| 366 |
+
atom_scope, bond_scope = [], []
|
| 367 |
+
|
| 368 |
+
for bid, graph_feature in enumerate(graph_features):
|
| 369 |
+
a_scope, b_scope, atom_features, bond_features, a_graph, b_graph = graph_feature
|
| 370 |
+
|
| 371 |
+
a_scope = a_scope.copy()
|
| 372 |
+
b_scope = b_scope.copy()
|
| 373 |
+
atom_features = atom_features.copy()
|
| 374 |
+
bond_features = bond_features.copy()
|
| 375 |
+
a_graph = a_graph.copy()
|
| 376 |
+
b_graph = b_graph.copy()
|
| 377 |
+
|
| 378 |
+
atom_offset = len(fnode)
|
| 379 |
+
bond_offset = n_unique_bonds
|
| 380 |
+
n_unique_bonds += int(bond_features.shape[0] / 2) # This should be correct?
|
| 381 |
+
|
| 382 |
+
a_scope[:, 0] += atom_offset
|
| 383 |
+
b_scope[:, 0] += bond_offset
|
| 384 |
+
atom_scope.append(a_scope)
|
| 385 |
+
bond_scope.append(b_scope)
|
| 386 |
+
|
| 387 |
+
# node iteration is reduced to an extend
|
| 388 |
+
fnode.extend(atom_features)
|
| 389 |
+
|
| 390 |
+
# edge iteration is reduced to an append
|
| 391 |
+
bond_features[:, :2] += atom_offset
|
| 392 |
+
fmess.append(bond_features)
|
| 393 |
+
|
| 394 |
+
a_graph += edge_offset
|
| 395 |
+
a_graph[a_graph >= 999999999] = 0 # resetting padding edge to point towards edge 0
|
| 396 |
+
agraph.append(a_graph)
|
| 397 |
+
|
| 398 |
+
b_graph += edge_offset
|
| 399 |
+
b_graph[b_graph >= 999999999] = 0 # resetting padding edge to point towards edge 0
|
| 400 |
+
bgraph.append(b_graph)
|
| 401 |
+
|
| 402 |
+
edge_offset += bond_features.shape[0]
|
| 403 |
+
|
| 404 |
+
# densification
|
| 405 |
+
fnode = np.stack(fnode, axis=0)
|
| 406 |
+
fnode_one_hot = np.zeros([fnode.shape[0], sum(ATOM_FDIM)], dtype=np.float32)
|
| 407 |
+
|
| 408 |
+
for i in range(len(ATOM_FDIM) - 1):
|
| 409 |
+
fnode[:, i+1:] += ATOM_FDIM[i] # cumsum, essentially
|
| 410 |
+
|
| 411 |
+
for i, feat in enumerate(fnode): # Looks vectorizable?
|
| 412 |
+
# fnode_one_hot[i, feat[feat < 9999]] = 1
|
| 413 |
+
fnode_one_hot[i, feat[feat < sum(ATOM_FDIM)]] = 1
|
| 414 |
+
|
| 415 |
+
fnode = torch.as_tensor(fnode_one_hot, dtype=torch.float)
|
| 416 |
+
fmess = torch.as_tensor(np.concatenate(fmess, axis=0), dtype=torch.float)
|
| 417 |
+
|
| 418 |
+
agraph = np.concatenate(agraph, axis=0)
|
| 419 |
+
column_idx = np.argwhere(np.all(agraph[..., :] == 0, axis=0))
|
| 420 |
+
agraph = agraph[:, :column_idx[0, 0] + 1] # drop trailing columns of 0, leaving only 1 last column of 0
|
| 421 |
+
|
| 422 |
+
bgraph = np.concatenate(bgraph, axis=0)
|
| 423 |
+
column_idx = np.argwhere(np.all(bgraph[..., :] == 0, axis=0))
|
| 424 |
+
bgraph = bgraph[:, :column_idx[0, 0] + 1] # drop trailing columns of 0, leaving only 1 last column of 0
|
| 425 |
+
|
| 426 |
+
agraph = torch.as_tensor(agraph, dtype=torch.long)
|
| 427 |
+
bgraph = torch.as_tensor(bgraph, dtype=torch.long)
|
| 428 |
+
|
| 429 |
+
else:
|
| 430 |
+
raise NotImplementedError
|
| 431 |
+
|
| 432 |
+
return fnode, fmess, agraph, bgraph, atom_scope, bond_scope
|
| 433 |
+
|
| 434 |
+
|
| 435 |
+
def collate_graph_distances(args, graph_features: List[Tuple], a_lengths: List[int],
|
| 436 |
+
distance_calculator=None) -> torch.Tensor:
|
| 437 |
+
max_len = max(a_lengths)
|
| 438 |
+
|
| 439 |
+
distances = []
|
| 440 |
+
for bid, (graph_feature, a_length) in enumerate(zip(graph_features, a_lengths)):
|
| 441 |
+
_, _, _, bond_features, _, _ = graph_feature
|
| 442 |
+
bond_features = bond_features.copy()
|
| 443 |
+
|
| 444 |
+
# compute adjacency
|
| 445 |
+
adjacency = np.zeros((a_length, a_length), dtype=np.bool_)
|
| 446 |
+
for bond_feature in bond_features:
|
| 447 |
+
u, v = bond_feature[:2]
|
| 448 |
+
adjacency[u, v] = True
|
| 449 |
+
|
| 450 |
+
distance = distance_calculator.calculate(adjacency, a_length, max_distance=a_length)
|
| 451 |
+
|
| 452 |
+
# bucket
|
| 453 |
+
distance[(distance > 8) & (distance < 15)] = 8
|
| 454 |
+
distance[distance >= 15] = 9
|
| 455 |
+
distance[distance == 0] = 10
|
| 456 |
+
|
| 457 |
+
# reset diagonal
|
| 458 |
+
np.fill_diagonal(distance, 0)
|
| 459 |
+
|
| 460 |
+
"""
|
| 461 |
+
graph_distance = distance.copy()
|
| 462 |
+
|
| 463 |
+
# compute graph distance
|
| 464 |
+
distance = adjacency.copy()
|
| 465 |
+
shortest_paths = adjacency.copy()
|
| 466 |
+
path_length = 2
|
| 467 |
+
stop_counter = 0
|
| 468 |
+
non_zeros = 0
|
| 469 |
+
|
| 470 |
+
while 0 in distance:
|
| 471 |
+
shortest_paths = np.matmul(shortest_paths, adjacency)
|
| 472 |
+
shortest_paths = path_length * (shortest_paths > 0)
|
| 473 |
+
new_distance = distance + (distance == 0) * shortest_paths
|
| 474 |
+
|
| 475 |
+
# if np.count_nonzero(new_distance) == np.count_nonzero(distance):
|
| 476 |
+
if np.count_nonzero(new_distance) <= non_zeros:
|
| 477 |
+
stop_counter += 1
|
| 478 |
+
else:
|
| 479 |
+
non_zeros = np.count_nonzero(new_distance)
|
| 480 |
+
stop_counter = 0
|
| 481 |
+
|
| 482 |
+
if args.task == "reaction_prediction" and stop_counter == 3:
|
| 483 |
+
break
|
| 484 |
+
|
| 485 |
+
distance = new_distance
|
| 486 |
+
path_length += 1
|
| 487 |
+
|
| 488 |
+
# bucket
|
| 489 |
+
distance[(distance > 8) & (distance < 15)] = 8
|
| 490 |
+
distance[distance >= 15] = 9
|
| 491 |
+
distance[distance == 0] = 10 # different molecules
|
| 492 |
+
|
| 493 |
+
# reset diagonal
|
| 494 |
+
np.fill_diagonal(distance, 0)
|
| 495 |
+
"""
|
| 496 |
+
|
| 497 |
+
# padding
|
| 498 |
+
# padded_distance = np.ones((max_len, max_len), dtype=np.uint8) * 11
|
| 499 |
+
padded_distance = np.ones((max_len, max_len), dtype=np.uint8) * (args.rel_pos_buckets + 1)
|
| 500 |
+
# padded_distance[:a_length, :a_length] = graph_distance
|
| 501 |
+
padded_distance[:a_length, :a_length] = distance
|
| 502 |
+
|
| 503 |
+
# assert np.array_equal(padded_distance[:a_length, :a_length], distance), \
|
| 504 |
+
# f"padded_distance:\n{padded_distance[:a_length, :a_length]}\n" \
|
| 505 |
+
# f"distance:\n{distance}"
|
| 506 |
+
|
| 507 |
+
distances.append(padded_distance)
|
| 508 |
+
|
| 509 |
+
distances = np.stack(distances)
|
| 510 |
+
distances = torch.as_tensor(distances, dtype=torch.long)
|
| 511 |
+
|
| 512 |
+
return distances
|
checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/graph2smiles_runtime/utils/parsing.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from utils.train_utils import log_rank_0
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def log_args(args, phase: str):
|
| 5 |
+
log_rank_0(f"Logging {phase} arguments")
|
| 6 |
+
for k, v in vars(args).items():
|
| 7 |
+
log_rank_0(f"**** {k} = *{v}*")
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def add_common_args(parser):
|
| 11 |
+
group = parser.add_argument_group("Meta")
|
| 12 |
+
group.add_argument("--model", help="Model architecture",
|
| 13 |
+
choices=["graph2smiles"], type=str, default="graph2smiles")
|
| 14 |
+
group.add_argument("--data_name", help="Data name", type=str, default="")
|
| 15 |
+
group.add_argument("--task", help="Task", choices=["reaction_prediction", "retrosynthesis", "autoencoding"],
|
| 16 |
+
type=str, default="reaction_prediction")
|
| 17 |
+
group.add_argument("--seed", help="Random seed", type=int, default=42)
|
| 18 |
+
group.add_argument("--max_src_len", help="Max source length", type=int, default=512)
|
| 19 |
+
group.add_argument("--max_tgt_len", help="Max target length", type=int, default=512)
|
| 20 |
+
group.add_argument("--num_cores", help="No. of workers", type=int, default=1)
|
| 21 |
+
group.add_argument("--verbose", help="Whether to enable verbose debugging", action="store_true")
|
| 22 |
+
|
| 23 |
+
group = parser.add_argument_group("Paths")
|
| 24 |
+
group.add_argument("--log_file", help="Preprocess log file", type=str, default="")
|
| 25 |
+
group.add_argument("--processed_data_path", help="Path for saving preprocessed outputs",
|
| 26 |
+
type=str, default="")
|
| 27 |
+
group.add_argument("--model_path", help="Path for saving checkpoints", type=str, default="")
|
| 28 |
+
group.add_argument("--test_output_path", help="Path for saving test outputs", type=str, default="")
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def add_preprocess_args(parser):
|
| 32 |
+
group = parser.add_argument_group("Preprocessing options")
|
| 33 |
+
# data paths
|
| 34 |
+
group.add_argument("--train_file", help="Train file", type=str, default="")
|
| 35 |
+
group.add_argument("--val_file", help="Validation file", type=str, default="")
|
| 36 |
+
group.add_argument("--test_file", help="Test file", type=str, default="")
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def add_train_args(parser):
|
| 40 |
+
group = parser.add_argument_group("Training options")
|
| 41 |
+
# file paths
|
| 42 |
+
group.add_argument("--load_from", help="Checkpoint to load", type=str, default="")
|
| 43 |
+
# model params
|
| 44 |
+
group.add_argument("--embed_size", help="Decoder embedding size", type=int, default=256)
|
| 45 |
+
group.add_argument("--share_embeddings", help="Whether to share encoder/decoder embeddings", action="store_true")
|
| 46 |
+
group.add_argument("--mask_rel_chirality", help="Whether to mask relative chirality", type=int, default=0)
|
| 47 |
+
group.add_argument("--shared_attention_layer", help="Whether to share attention layer", type=int, default=0)
|
| 48 |
+
# latent modeling
|
| 49 |
+
group.add_argument("--n_latent", help="Latent modeling mode or number of latent class", type=str, default="1")
|
| 50 |
+
# -------------- mpn encoder ---------------
|
| 51 |
+
group.add_argument("--mpn_type", help="Type of MPN", type=str,
|
| 52 |
+
choices=["dgcn", "dgat"], default="dgcn")
|
| 53 |
+
group.add_argument("--encoder_num_layers", help="No. of layers in transformer/mpn encoder", type=int, default=4)
|
| 54 |
+
group.add_argument("--dgat_attn_heads", help="DGAT no. of attention heads", type=int, default=8)
|
| 55 |
+
group.add_argument("--encoder_hidden_size", help="Encoder hidden size", type=int, default=256)
|
| 56 |
+
group.add_argument("--encoder_attn_heads", help="Encoder no. of attention heads", type=int, default=8)
|
| 57 |
+
group.add_argument("--encoder_filter_size", help="Encoder filter size", type=int, default=2048)
|
| 58 |
+
group.add_argument("--encoder_norm", help="Encoder norm", type=str, default="none")
|
| 59 |
+
group.add_argument("--encoder_skip_connection", help="Encoder skip connection", type=str, default="none")
|
| 60 |
+
group.add_argument("--encoder_positional_encoding", help="Encoder positional encoding", type=str, default="")
|
| 61 |
+
group.add_argument("--encoder_emb_scale", help="How to scale encoder embedding", type=str, default="")
|
| 62 |
+
# -------------- attention encoder ---------------
|
| 63 |
+
group.add_argument("--compute_graph_distance", help="Whether to compute graph distance", action="store_true")
|
| 64 |
+
group.add_argument("--attn_enc_num_layers", help="No. of layers", type=int, default=4)
|
| 65 |
+
group.add_argument("--attn_enc_hidden_size", help="Hidden size", type=int, default=256)
|
| 66 |
+
group.add_argument("--attn_enc_heads", help="Hidden size", type=int, default=8)
|
| 67 |
+
group.add_argument("--attn_enc_filter_size", help="Filter size", type=int, default=2048)
|
| 68 |
+
group.add_argument("--rel_pos", help="type of rel. pos.", type=str, default="none")
|
| 69 |
+
group.add_argument("--rel_pos_buckets", help="No. of relative position buckets", type=int, default=10)
|
| 70 |
+
# -------------- Transformer decoder ---------------
|
| 71 |
+
group.add_argument("--decoder_num_layers", help="No. of layers in transformer decoder", type=int, default=4)
|
| 72 |
+
group.add_argument("--decoder_hidden_size", help="Decoder hidden size", type=int, default=256)
|
| 73 |
+
group.add_argument("--decoder_attn_heads", help="Decoder no. of attention heads", type=int, default=8)
|
| 74 |
+
group.add_argument("--decoder_filter_size", help="Decoder filter size", type=int, default=2048)
|
| 75 |
+
group.add_argument("--dropout", help="Hidden dropout", type=float, default=0.0)
|
| 76 |
+
group.add_argument("--attn_dropout", help="Attention dropout", type=float, default=0.0)
|
| 77 |
+
group.add_argument("--max_relative_positions", help="Max relative positions", type=int, default=0)
|
| 78 |
+
# training params
|
| 79 |
+
group.add_argument('--local_rank', type=int, default=-1, metavar='N', help='Local process rank')
|
| 80 |
+
group.add_argument("--enable_amp", help="Whether to enable mixed precision training", action="store_true")
|
| 81 |
+
group.add_argument("--resume", help="Whether to resume training", action="store_true")
|
| 82 |
+
group.add_argument("--backend", help="Backend for DDP", type=str, default="gloo")
|
| 83 |
+
group.add_argument("--epoch", help="Number of training epochs", type=int, default=300)
|
| 84 |
+
group.add_argument("--max_steps", help="Number of max total steps", type=int, default=1000000)
|
| 85 |
+
group.add_argument("--warmup_steps", help="Number of warmup steps", type=int, default=8000)
|
| 86 |
+
group.add_argument("--lr", help="Learning rate", type=float, default=0.0)
|
| 87 |
+
group.add_argument("--beta1", help="Adam beta 1", type=float, default=0.9)
|
| 88 |
+
group.add_argument("--beta2", help="Adam beta 2", type=float, default=0.998)
|
| 89 |
+
group.add_argument("--eps", help="Adam epsilon", type=float, default=1e-9)
|
| 90 |
+
group.add_argument("--weight_decay", help="Adam weight decay", type=float, default=1e-2)
|
| 91 |
+
group.add_argument("--clip_norm", help="Max norm for gradient clipping", type=float, default=20.0)
|
| 92 |
+
group.add_argument("--batch_type", help="batch type", type=str, default="tokens")
|
| 93 |
+
group.add_argument("--train_batch_size", help="Batch size for train", type=int, default=4096)
|
| 94 |
+
group.add_argument("--val_batch_size", help="Batch size for valid", type=int, default=4096)
|
| 95 |
+
group.add_argument("--accumulation_count", help="No. of batches for gradient accumulation", type=int, default=1)
|
| 96 |
+
group.add_argument("--log_iter", help="No. of steps per logging", type=int, default=100)
|
| 97 |
+
group.add_argument("--eval_iter", help="No. of steps per evaluation", type=int, default=100)
|
| 98 |
+
group.add_argument("--save_iter", help="No. of steps per saving", type=int, default=100)
|
| 99 |
+
# debug params
|
| 100 |
+
group.add_argument("--do_profile", help="Whether to do profiling", action="store_true")
|
| 101 |
+
group.add_argument("--record_shapes", help="Whether to record tensor shapes for profiling", action="store_true")
|
| 102 |
+
|
| 103 |
+
return parser
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def add_predict_args(parser):
|
| 107 |
+
group = parser.add_argument_group("Prediction options")
|
| 108 |
+
group.add_argument("--do_validate", help="Whether to do validation", action="store_true")
|
| 109 |
+
group.add_argument("--do_predict", help="Whether to do prediction", action="store_true")
|
| 110 |
+
group.add_argument("--do_score", help="Whether to score predictions", action="store_true")
|
| 111 |
+
group.add_argument("--checkpoint_step_start", help="First checkpoint step", type=int)
|
| 112 |
+
group.add_argument("--checkpoint_step_end", help="Last checkpoint step", type=int)
|
| 113 |
+
group.add_argument("--predict_batch_size", help="Batch size for prediction", type=int, default=4096)
|
| 114 |
+
# decoding params
|
| 115 |
+
group.add_argument("--result_file", help="Result file", type=str, default="")
|
| 116 |
+
group.add_argument("--beam_size", help="Beam size for decoding", type=int, default=0)
|
| 117 |
+
group.add_argument("--n_best", help="Number of best results to be retained", type=int, default=10)
|
| 118 |
+
group.add_argument("--temperature", help="Beam search temperature", type=float, default=1.0)
|
| 119 |
+
group.add_argument("--predict_min_len", help="Min length for prediction", type=int, default=1)
|
| 120 |
+
group.add_argument("--predict_max_len", help="Max length for prediction", type=int, default=512)
|
checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/graph2smiles_runtime/utils/preprocess_utils.py
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import networkx as nx
|
| 3 |
+
import numpy as np
|
| 4 |
+
import os
|
| 5 |
+
import re
|
| 6 |
+
from rdkit import Chem
|
| 7 |
+
from typing import Dict, List, Tuple
|
| 8 |
+
from utils.chem_utils import get_atom_features_sparse, get_bond_features
|
| 9 |
+
from utils.rxn_graphs import RxnGraph
|
| 10 |
+
from utils.train_utils import log_rank_0
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def smi_tokenizer(smi: str):
|
| 14 |
+
"""Tokenize a SMILES molecule or reaction, adapted from https://github.com/pschwllr/MolecularTransformer"""
|
| 15 |
+
pattern = "(\[[^\]]+]|Br?|Cl?|N|O|S|P|F|I|b|c|n|o|s|p|\(|\)|\.|=|#|-|\+|\\\\|\/|:|~|@|\?|>|\*|\$|\%[0-9]{2}|[0-9])"
|
| 16 |
+
regex = re.compile(pattern)
|
| 17 |
+
tokens = [token for token in regex.findall(smi)]
|
| 18 |
+
assert smi == "".join(tokens)
|
| 19 |
+
|
| 20 |
+
return " ".join(tokens)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def get_token_ids(tokens: list, vocab: Dict[str, int], max_len: int) -> Tuple[List, int]:
|
| 24 |
+
token_ids = []
|
| 25 |
+
token_ids.extend([vocab[token] for token in tokens])
|
| 26 |
+
token_ids = token_ids[:max_len-1]
|
| 27 |
+
token_ids.append(vocab["_EOS"])
|
| 28 |
+
|
| 29 |
+
lens = len(token_ids)
|
| 30 |
+
while len(token_ids) < max_len:
|
| 31 |
+
token_ids.append(vocab["_PAD"])
|
| 32 |
+
|
| 33 |
+
return token_ids, lens
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def get_graph_from_smiles(smi: str):
|
| 37 |
+
mol = Chem.MolFromSmiles(smi)
|
| 38 |
+
if mol is None or mol.GetNumBonds() == 0:
|
| 39 |
+
mol = Chem.MolFromSmiles("CC") # hardcode to ignore
|
| 40 |
+
rxn_graph = RxnGraph(reac_mol=mol)
|
| 41 |
+
|
| 42 |
+
return rxn_graph
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def get_graph_features_from_smi(_args):
|
| 46 |
+
i, smi = _args
|
| 47 |
+
assert isinstance(smi, str)
|
| 48 |
+
if i > 0 and i % 10000 == 0:
|
| 49 |
+
logging.info(f"Processing {i}th SMILES")
|
| 50 |
+
|
| 51 |
+
atom_features = []
|
| 52 |
+
bond_features = []
|
| 53 |
+
edge_dict = {}
|
| 54 |
+
|
| 55 |
+
if not smi.strip():
|
| 56 |
+
smi = "CC" # hardcode to ignore
|
| 57 |
+
|
| 58 |
+
smi = "".join(smi.split())
|
| 59 |
+
graph = get_graph_from_smiles(smi).reac_mol
|
| 60 |
+
|
| 61 |
+
mol = graph.mol
|
| 62 |
+
assert mol.GetNumAtoms() == len(graph.G_dir)
|
| 63 |
+
|
| 64 |
+
G = nx.convert_node_labels_to_integers(graph.G_dir, first_label=0)
|
| 65 |
+
|
| 66 |
+
# node iteration to get sparse atom features
|
| 67 |
+
for v, attr in G.nodes(data="label"):
|
| 68 |
+
atom_feat = get_atom_features_sparse(mol.GetAtomWithIdx(v))
|
| 69 |
+
atom_features.append(atom_feat)
|
| 70 |
+
|
| 71 |
+
a_graphs = [[] for _ in range(len(atom_features))]
|
| 72 |
+
|
| 73 |
+
# edge iteration to get (dense) bond features
|
| 74 |
+
for u, v, attr in G.edges(data='label'):
|
| 75 |
+
bond_feat = get_bond_features(mol.GetBondBetweenAtoms(u, v))
|
| 76 |
+
bond_feat = [u, v] + bond_feat
|
| 77 |
+
bond_features.append(bond_feat)
|
| 78 |
+
|
| 79 |
+
eid = len(edge_dict)
|
| 80 |
+
edge_dict[(u, v)] = eid
|
| 81 |
+
a_graphs[v].append(eid)
|
| 82 |
+
|
| 83 |
+
b_graphs = [[] for _ in range(len(bond_features))]
|
| 84 |
+
|
| 85 |
+
# second edge iteration to get neighboring edges (after edge_dict is updated fully)
|
| 86 |
+
for bond_feat in bond_features:
|
| 87 |
+
u, v = bond_feat[:2]
|
| 88 |
+
eid = edge_dict[(u, v)]
|
| 89 |
+
|
| 90 |
+
for w in G.predecessors(u):
|
| 91 |
+
if not w == v:
|
| 92 |
+
b_graphs[eid].append(edge_dict[(w, u)])
|
| 93 |
+
|
| 94 |
+
# padding
|
| 95 |
+
for a_graph in a_graphs:
|
| 96 |
+
while len(a_graph) < 11: # OH MY GOODNESS... Fe can be bonded to 10...
|
| 97 |
+
a_graph.append(1e9)
|
| 98 |
+
|
| 99 |
+
for b_graph in b_graphs:
|
| 100 |
+
while len(b_graph) < 11: # OH MY GOODNESS... Fe can be bonded to 10...
|
| 101 |
+
b_graph.append(1e9)
|
| 102 |
+
|
| 103 |
+
a_scopes = np.array(graph.atom_scope, dtype=np.int32)
|
| 104 |
+
a_scopes_lens = a_scopes.shape[0]
|
| 105 |
+
b_scopes = np.array(graph.bond_scope, dtype=np.int32)
|
| 106 |
+
b_scopes_lens = b_scopes.shape[0]
|
| 107 |
+
a_features = np.array(atom_features, dtype=np.int32)
|
| 108 |
+
a_features_lens = a_features.shape[0]
|
| 109 |
+
b_features = np.array(bond_features, dtype=np.int32)
|
| 110 |
+
b_features_lens = b_features.shape[0]
|
| 111 |
+
a_graphs = np.array(a_graphs, dtype=np.int32)
|
| 112 |
+
b_graphs = np.array(b_graphs, dtype=np.int32)
|
| 113 |
+
|
| 114 |
+
return a_scopes, a_scopes_lens, b_scopes, b_scopes_lens, \
|
| 115 |
+
a_features, a_features_lens, b_features, b_features_lens, a_graphs, b_graphs
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def make_vocab(args):
|
| 119 |
+
logging.info(f"Making vocab")
|
| 120 |
+
vocab = {}
|
| 121 |
+
|
| 122 |
+
for phase in ["train", "val", "test"]:
|
| 123 |
+
for fn in [
|
| 124 |
+
os.path.join(args.processed_data_path, f"src-{phase}.txt"),
|
| 125 |
+
os.path.join(args.processed_data_path, f"tgt-{phase}.txt")
|
| 126 |
+
]:
|
| 127 |
+
with open(fn, "r") as f:
|
| 128 |
+
for line in f:
|
| 129 |
+
tokens = line.strip().split()
|
| 130 |
+
for token in tokens:
|
| 131 |
+
if token in vocab:
|
| 132 |
+
vocab[token] += 1
|
| 133 |
+
else:
|
| 134 |
+
vocab[token] = 1
|
| 135 |
+
|
| 136 |
+
vocab_file = os.path.join(args.processed_data_path, "vocab.txt")
|
| 137 |
+
logging.info(f"Saving vocab into {vocab_file}")
|
| 138 |
+
with open(vocab_file, "w") as of:
|
| 139 |
+
of.write("_PAD\n_UNK\n_SOS\n_EOS\n")
|
| 140 |
+
for token, count in vocab.items():
|
| 141 |
+
of.write(f"{token}\t{count}\n")
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def load_vocab(args) -> Dict[str, int]:
|
| 145 |
+
vocab_file = os.path.join(args.processed_data_path, "vocab.txt")
|
| 146 |
+
log_rank_0(f"Loading vocab from {vocab_file}")
|
| 147 |
+
vocab = {}
|
| 148 |
+
with open(vocab_file, "r") as f:
|
| 149 |
+
for i, line in enumerate(f):
|
| 150 |
+
token = line.strip().split("\t")[0]
|
| 151 |
+
vocab[token] = i
|
| 152 |
+
|
| 153 |
+
return vocab
|
checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/graph2smiles_runtime/utils/rxn_graphs.py
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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kit import Chem
|
| 4 |
+
from typing import List, Tuple, Union
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def get_sub_mol(mol, sub_atoms):
|
| 8 |
+
new_mol = Chem.RWMol()
|
| 9 |
+
atom_map = {}
|
| 10 |
+
for idx in sub_atoms:
|
| 11 |
+
atom = mol.GetAtomWithIdx(idx)
|
| 12 |
+
atom_map[idx] = new_mol.AddAtom(atom)
|
| 13 |
+
|
| 14 |
+
sub_atoms = set(sub_atoms)
|
| 15 |
+
for idx in sub_atoms:
|
| 16 |
+
a = mol.GetAtomWithIdx(idx)
|
| 17 |
+
for b in a.GetNeighbors():
|
| 18 |
+
if b.GetIdx() not in sub_atoms:
|
| 19 |
+
continue
|
| 20 |
+
bond = mol.GetBondBetweenAtoms(a.GetIdx(), b.GetIdx())
|
| 21 |
+
bt = bond.GetBondType()
|
| 22 |
+
if a.GetIdx() < b.GetIdx(): # each bond is enumerated twice
|
| 23 |
+
new_mol.AddBond(atom_map[a.GetIdx()], atom_map[b.GetIdx()], bt)
|
| 24 |
+
|
| 25 |
+
return new_mol.GetMol()
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class RxnGraph:
|
| 29 |
+
"""
|
| 30 |
+
RxnGraph is an abstract class for storing all elements of a reaction, like
|
| 31 |
+
reactants, products and fragments. The edits associated with the reaction
|
| 32 |
+
are also captured in edit labels. One can also use h_labels, which keep track
|
| 33 |
+
of atoms with hydrogen changes. For reactions with multiple edits, a done
|
| 34 |
+
label is also added to account for termination of edits.
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
def __init__(self,
|
| 38 |
+
prod_mol: Chem.Mol = None,
|
| 39 |
+
frag_mol: Chem.Mol = None,
|
| 40 |
+
reac_mol: Chem.Mol = None,
|
| 41 |
+
rxn_class: int = None) -> None:
|
| 42 |
+
"""
|
| 43 |
+
Parameters
|
| 44 |
+
----------
|
| 45 |
+
prod_mol: Chem.Mol,
|
| 46 |
+
Product molecule
|
| 47 |
+
frag_mol: Chem.Mol, default None
|
| 48 |
+
Fragment molecule(s)
|
| 49 |
+
reac_mol: Chem.Mol, default None
|
| 50 |
+
Reactant molecule(s)
|
| 51 |
+
rxn_class: int, default None,
|
| 52 |
+
Reaction class for this reaction.
|
| 53 |
+
"""
|
| 54 |
+
if prod_mol is not None:
|
| 55 |
+
self.prod_mol = RxnElement(mol=prod_mol, rxn_class=rxn_class)
|
| 56 |
+
if frag_mol is not None:
|
| 57 |
+
self.frag_mol = MultiElement(mol=frag_mol, rxn_class=rxn_class)
|
| 58 |
+
if reac_mol is not None:
|
| 59 |
+
self.reac_mol = MultiElement(mol=reac_mol, rxn_class=rxn_class)
|
| 60 |
+
self.rxn_class = rxn_class
|
| 61 |
+
|
| 62 |
+
def get_attributes(self, mol_attrs: Tuple = ('prod_mol', 'frag_mol', 'reac_mol')) -> Tuple:
|
| 63 |
+
"""
|
| 64 |
+
Returns the different attributes associated with the reaction graph.
|
| 65 |
+
|
| 66 |
+
Parameters
|
| 67 |
+
----------
|
| 68 |
+
mol_attrs: Tuple,
|
| 69 |
+
Molecule objects to return
|
| 70 |
+
"""
|
| 71 |
+
return tuple(getattr(self, attr) for attr in mol_attrs if hasattr(self, attr))
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
class RxnElement:
|
| 75 |
+
"""
|
| 76 |
+
RxnElement is an abstract class for dealing with single molecule. The graph
|
| 77 |
+
and corresponding molecule attributes are built for the molecule. The constructor
|
| 78 |
+
accepts only mol objects, sidestepping the use of SMILES string which may always
|
| 79 |
+
not be achievable, especially for a unkekulizable molecule.
|
| 80 |
+
"""
|
| 81 |
+
|
| 82 |
+
def __init__(self, mol: Chem.Mol, rxn_class: int = None) -> None:
|
| 83 |
+
"""
|
| 84 |
+
Parameters
|
| 85 |
+
----------
|
| 86 |
+
mol: Chem.Mol,
|
| 87 |
+
Molecule
|
| 88 |
+
rxn_class: int, default None,
|
| 89 |
+
Reaction class for this reaction.
|
| 90 |
+
"""
|
| 91 |
+
self.mol = mol
|
| 92 |
+
self.rxn_class = rxn_class
|
| 93 |
+
self._build_mol()
|
| 94 |
+
self._build_graph()
|
| 95 |
+
|
| 96 |
+
def _build_mol(self) -> None:
|
| 97 |
+
"""Builds the molecule attributes."""
|
| 98 |
+
self.num_atoms = self.mol.GetNumAtoms()
|
| 99 |
+
self.num_bonds = self.mol.GetNumBonds()
|
| 100 |
+
self.amap_to_idx = {atom.GetAtomMapNum(): atom.GetIdx()
|
| 101 |
+
for atom in self.mol.GetAtoms()}
|
| 102 |
+
self.idx_to_amap = {value: key for key, value in self.amap_to_idx.items()}
|
| 103 |
+
|
| 104 |
+
def _build_graph(self) -> None:
|
| 105 |
+
"""Builds the graph attributes."""
|
| 106 |
+
self.G_undir = nx.Graph(Chem.rdmolops.GetAdjacencyMatrix(self.mol))
|
| 107 |
+
self.G_dir = nx.DiGraph(Chem.rdmolops.GetAdjacencyMatrix(self.mol))
|
| 108 |
+
|
| 109 |
+
for atom in self.mol.GetAtoms():
|
| 110 |
+
self.G_undir.nodes[atom.GetIdx()]['label'] = atom.GetSymbol()
|
| 111 |
+
self.G_dir.nodes[atom.GetIdx()]['label'] = atom.GetSymbol()
|
| 112 |
+
|
| 113 |
+
for bond in self.mol.GetBonds():
|
| 114 |
+
a1 = bond.GetBeginAtom().GetIdx()
|
| 115 |
+
a2 = bond.GetEndAtom().GetIdx()
|
| 116 |
+
btype = BOND_TYPES.index(bond.GetBondType())
|
| 117 |
+
self.G_undir[a1][a2]['label'] = btype
|
| 118 |
+
self.G_dir[a1][a2]['label'] = btype
|
| 119 |
+
self.G_dir[a2][a1]['label'] = btype
|
| 120 |
+
|
| 121 |
+
self.atom_scope = (0, self.num_atoms)
|
| 122 |
+
self.bond_scope = (0, self.num_bonds)
|
| 123 |
+
|
| 124 |
+
def update_atom_scope(self, offset: int) -> Union[List, Tuple]:
|
| 125 |
+
"""Updates the atom indices by the offset.
|
| 126 |
+
|
| 127 |
+
Parameters
|
| 128 |
+
----------
|
| 129 |
+
offset: int,
|
| 130 |
+
Offset to apply
|
| 131 |
+
"""
|
| 132 |
+
# Note that the self. reference to atom_scope is dropped to keep self.atom_scope non-dynamic
|
| 133 |
+
if isinstance(self.atom_scope, list):
|
| 134 |
+
atom_scope = [(st + offset, le) for st, le in self.atom_scope]
|
| 135 |
+
else:
|
| 136 |
+
st, le = self.atom_scope
|
| 137 |
+
atom_scope = (st + offset, le)
|
| 138 |
+
|
| 139 |
+
return atom_scope
|
| 140 |
+
|
| 141 |
+
def update_bond_scope(self, offset: int) -> Union[List, Tuple]:
|
| 142 |
+
"""Updates the bond indices by the offset.
|
| 143 |
+
|
| 144 |
+
Parameters
|
| 145 |
+
----------
|
| 146 |
+
offset: int,
|
| 147 |
+
Offset to apply
|
| 148 |
+
"""
|
| 149 |
+
# Note that the self. reference to bond_scope is dropped to keep self.bond_scope non-dynamic
|
| 150 |
+
if isinstance(self.bond_scope, list):
|
| 151 |
+
bond_scope = [(st + offset, le) for st, le in self.bond_scope]
|
| 152 |
+
else:
|
| 153 |
+
st, le = self.bond_scope
|
| 154 |
+
bond_scope = (st + offset, le)
|
| 155 |
+
|
| 156 |
+
return bond_scope
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
class MultiElement(RxnElement):
|
| 160 |
+
"""
|
| 161 |
+
MultiElement is an abstract class for dealing with multiple molecules. The graph
|
| 162 |
+
is built with all molecules, but different molecules and their sizes are stored.
|
| 163 |
+
The constructor accepts only mol objects, sidestepping the use of SMILES string
|
| 164 |
+
which may always not be achievable, especially for an invalid intermediates.
|
| 165 |
+
"""
|
| 166 |
+
|
| 167 |
+
def _build_graph(self) -> None:
|
| 168 |
+
"""Builds the graph attributes."""
|
| 169 |
+
self.G_undir = nx.Graph(Chem.rdmolops.GetAdjacencyMatrix(self.mol))
|
| 170 |
+
self.G_dir = nx.DiGraph(Chem.rdmolops.GetAdjacencyMatrix(self.mol))
|
| 171 |
+
|
| 172 |
+
for atom in self.mol.GetAtoms():
|
| 173 |
+
self.G_undir.nodes[atom.GetIdx()]['label'] = atom.GetSymbol()
|
| 174 |
+
self.G_dir.nodes[atom.GetIdx()]['label'] = atom.GetSymbol()
|
| 175 |
+
|
| 176 |
+
for bond in self.mol.GetBonds():
|
| 177 |
+
a1 = bond.GetBeginAtom().GetIdx()
|
| 178 |
+
a2 = bond.GetEndAtom().GetIdx()
|
| 179 |
+
btype = BOND_TYPES.index(bond.GetBondType())
|
| 180 |
+
self.G_undir[a1][a2]['label'] = btype
|
| 181 |
+
self.G_dir[a1][a2]['label'] = btype
|
| 182 |
+
self.G_dir[a2][a1]['label'] = btype
|
| 183 |
+
|
| 184 |
+
frag_indices = [c for c in nx.strongly_connected_components(self.G_dir)]
|
| 185 |
+
self.mols = [get_sub_mol(self.mol, sub_atoms) for sub_atoms in frag_indices]
|
| 186 |
+
|
| 187 |
+
atom_start = 0
|
| 188 |
+
bond_start = 0
|
| 189 |
+
self.atom_scope = []
|
| 190 |
+
self.bond_scope = []
|
| 191 |
+
|
| 192 |
+
for mol in self.mols:
|
| 193 |
+
self.atom_scope.append((atom_start, mol.GetNumAtoms()))
|
| 194 |
+
self.bond_scope.append((bond_start, mol.GetNumBonds()))
|
| 195 |
+
atom_start += mol.GetNumAtoms()
|
| 196 |
+
bond_start += mol.GetNumBonds()
|
checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/graph2smiles_runtime/utils/train_utils.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import math
|
| 3 |
+
import numpy as np
|
| 4 |
+
import os
|
| 5 |
+
import random
|
| 6 |
+
import sys
|
| 7 |
+
import torch
|
| 8 |
+
import torch.nn as nn
|
| 9 |
+
from datetime import datetime
|
| 10 |
+
from rdkit import RDLogger
|
| 11 |
+
from torch.optim.lr_scheduler import _LRScheduler
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def log_rank_0(message):
|
| 15 |
+
if torch.distributed.is_initialized():
|
| 16 |
+
if torch.distributed.get_rank() == 0:
|
| 17 |
+
logging.info(message)
|
| 18 |
+
sys.stdout.flush()
|
| 19 |
+
else:
|
| 20 |
+
logging.info(message)
|
| 21 |
+
sys.stdout.flush()
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def param_count(model: nn.Module) -> int:
|
| 25 |
+
return sum(param.numel() for param in model.parameters() if param.requires_grad)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def param_norm(m):
|
| 29 |
+
return math.sqrt(sum([p.norm().item() ** 2 for p in m.parameters()]))
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def grad_norm(m):
|
| 33 |
+
return math.sqrt(sum([p.grad.norm().item() ** 2 for p in m.parameters() if p.grad is not None]))
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def get_lr(optimizer):
|
| 37 |
+
for param_group in optimizer.param_groups:
|
| 38 |
+
return param_group["lr"]
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def set_seed(seed):
|
| 42 |
+
random.seed(seed)
|
| 43 |
+
os.environ['PYTHONHASHSEED'] = str(seed)
|
| 44 |
+
np.random.seed(seed)
|
| 45 |
+
torch.manual_seed(seed)
|
| 46 |
+
torch.cuda.manual_seed_all(seed)
|
| 47 |
+
torch.backends.cudnn.benchmark = False
|
| 48 |
+
torch.backends.cudnn.deterministic = True
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def setup_logger(args, warning_off: bool = False):
|
| 52 |
+
if warning_off:
|
| 53 |
+
RDLogger.DisableLog("rdApp.*")
|
| 54 |
+
else:
|
| 55 |
+
RDLogger.DisableLog("rdApp.warning")
|
| 56 |
+
|
| 57 |
+
os.makedirs(f"./logs/{args.data_name}", exist_ok=True)
|
| 58 |
+
dt = datetime.strftime(datetime.now(), "%y%m%d-%H%Mh")
|
| 59 |
+
|
| 60 |
+
logger = logging.getLogger()
|
| 61 |
+
logger.setLevel(logging.INFO)
|
| 62 |
+
fh = logging.FileHandler(f"./logs/{args.data_name}/{args.log_file}.{dt}")
|
| 63 |
+
sh = logging.StreamHandler(sys.stdout)
|
| 64 |
+
fh.setLevel(logging.INFO)
|
| 65 |
+
sh.setLevel(logging.INFO)
|
| 66 |
+
logger.addHandler(fh)
|
| 67 |
+
logger.addHandler(sh)
|
| 68 |
+
|
| 69 |
+
return logger
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def log_tensor(tensor, tensor_name: str, shape_only=False):
|
| 73 |
+
log_rank_0(f"--------------------------{tensor_name}--------------------------")
|
| 74 |
+
if not shape_only:
|
| 75 |
+
log_rank_0(tensor)
|
| 76 |
+
if isinstance(tensor, torch.Tensor):
|
| 77 |
+
log_rank_0(tensor.shape)
|
| 78 |
+
elif isinstance(tensor, np.ndarray):
|
| 79 |
+
log_rank_0(tensor.shape)
|
| 80 |
+
elif isinstance(tensor, list):
|
| 81 |
+
try:
|
| 82 |
+
for item in tensor:
|
| 83 |
+
log_rank_0(item.shape)
|
| 84 |
+
except Exception as e:
|
| 85 |
+
log_rank_0(f"Error: {e}")
|
| 86 |
+
log_rank_0("List items are not tensors, skip shape logging.")
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
class NoamLR(_LRScheduler):
|
| 90 |
+
"""
|
| 91 |
+
Adapted from https://github.com/tugstugi/pytorch-saltnet/blob/master/utils/lr_scheduler.py
|
| 92 |
+
|
| 93 |
+
Implements the Noam Learning rate schedule. This corresponds to increasing the learning rate
|
| 94 |
+
linearly for the first ``warmup_steps`` training steps, and decreasing it thereafter proportionally
|
| 95 |
+
to the inverse square root of the step number, scaled by the inverse square root of the
|
| 96 |
+
dimensionality of the model. Time will tell if this is just madness or it's actually important.
|
| 97 |
+
Parameters
|
| 98 |
+
----------
|
| 99 |
+
warmup_steps: ``int``, required.
|
| 100 |
+
The number of steps to linearly increase the learning rate.
|
| 101 |
+
"""
|
| 102 |
+
def __init__(self, optimizer, model_size, warmup_steps):
|
| 103 |
+
self.model_size = model_size
|
| 104 |
+
self.warmup_steps = warmup_steps
|
| 105 |
+
super().__init__(optimizer)
|
| 106 |
+
|
| 107 |
+
def get_lr(self):
|
| 108 |
+
step = max(1, self._step_count)
|
| 109 |
+
scale = self.model_size ** (-0.5) * min(step ** (-0.5), step * self.warmup_steps**(-1.5))
|
| 110 |
+
|
| 111 |
+
return [base_lr * scale for base_lr in self.base_lrs]
|
checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/mar_files/handler.py
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import glob
|
| 2 |
+
import numpy as np
|
| 3 |
+
import time
|
| 4 |
+
import torch
|
| 5 |
+
import zipfile
|
| 6 |
+
import numpy as np
|
| 7 |
+
from rdkit import Chem
|
| 8 |
+
from multiprocessing import Pool
|
| 9 |
+
from typing import Any, Dict, List
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class G2SHandler:
|
| 13 |
+
"""Graph2SMILES Handler for torchserve"""
|
| 14 |
+
|
| 15 |
+
def __init__(self):
|
| 16 |
+
self._context = None
|
| 17 |
+
self.manifest = None
|
| 18 |
+
self.initialized = False
|
| 19 |
+
|
| 20 |
+
self.args = None
|
| 21 |
+
self.device = None
|
| 22 |
+
self.model = None
|
| 23 |
+
self.vocab = None
|
| 24 |
+
self.vocab_tokens = None
|
| 25 |
+
self.distance_calculator = None
|
| 26 |
+
self.p = None
|
| 27 |
+
|
| 28 |
+
def overwrite_default_args(self):
|
| 29 |
+
# self.args.load_from = "model.400000_39.pt"
|
| 30 |
+
self.args.vocab_file = "vocab.txt"
|
| 31 |
+
# self.args.mask_rel_chirality = 1
|
| 32 |
+
self.args.mask_rel_chirality = 0
|
| 33 |
+
self.args.predict_batch_size = 16384
|
| 34 |
+
self.args.beam_size = 30
|
| 35 |
+
self.args.n_best = 30
|
| 36 |
+
self.args.temperature = 1.0
|
| 37 |
+
self.args.predict_min_len = 1
|
| 38 |
+
self.args.predict_max_len = 512
|
| 39 |
+
self.args.device = self.device
|
| 40 |
+
|
| 41 |
+
def initialize(self, context):
|
| 42 |
+
self._context = context
|
| 43 |
+
self.manifest = context.manifest
|
| 44 |
+
|
| 45 |
+
properties = context.system_properties
|
| 46 |
+
model_dir = properties.get("model_dir")
|
| 47 |
+
print(glob.glob(f"{model_dir}/*"))
|
| 48 |
+
self.device = torch.device("cuda:" + str(properties.get("gpu_id")) if torch.cuda.is_available() else "cpu")
|
| 49 |
+
|
| 50 |
+
with zipfile.ZipFile(model_dir + '/models.zip', 'r') as zip_ref:
|
| 51 |
+
zip_ref.extractall(model_dir)
|
| 52 |
+
with zipfile.ZipFile(model_dir + '/utils.zip', 'r') as zip_ref:
|
| 53 |
+
zip_ref.extractall(model_dir)
|
| 54 |
+
|
| 55 |
+
from train import get_model
|
| 56 |
+
from models.graph2smiles import Graph2SMILES
|
| 57 |
+
from predict import get_predict_parser
|
| 58 |
+
from utils import parsing
|
| 59 |
+
from utils.ctypes_calculator import DistanceCalculator
|
| 60 |
+
from utils.data_utils import load_vocab
|
| 61 |
+
|
| 62 |
+
predict_parser = get_predict_parser()
|
| 63 |
+
self.args, _ = predict_parser.parse_known_args()
|
| 64 |
+
self.overwrite_default_args()
|
| 65 |
+
|
| 66 |
+
checkpoint = model_dir + "/model.pt"
|
| 67 |
+
state = torch.load(checkpoint, map_location=self.device)
|
| 68 |
+
pretrain_args = state["args"]
|
| 69 |
+
pretrain_args.load_from = None
|
| 70 |
+
pretrain_state_dict = state["state_dict"]
|
| 71 |
+
|
| 72 |
+
# for backward compatibility
|
| 73 |
+
if not hasattr(pretrain_args, "shared_attention_layer"):
|
| 74 |
+
pretrain_args.shared_attention_layer = 0
|
| 75 |
+
if not hasattr(pretrain_args, "n_latent"):
|
| 76 |
+
pretrain_args.n_latent = 1
|
| 77 |
+
# pretrain_args.rel_pos_buckets -= 1
|
| 78 |
+
pretrain_args.local_rank = -1
|
| 79 |
+
# parsing.log_args(pretrain_args, phase="pretrained")
|
| 80 |
+
|
| 81 |
+
model_class = Graph2SMILES
|
| 82 |
+
|
| 83 |
+
self.args.processed_data_path = model_dir
|
| 84 |
+
self.vocab = load_vocab(self.args)
|
| 85 |
+
self.vocab_tokens = [k for k, v in sorted(self.vocab.items(), key=lambda tup: tup[1])]
|
| 86 |
+
|
| 87 |
+
model, state = get_model(pretrain_args, model_class, self.vocab, self.device)
|
| 88 |
+
# logging.info(model)
|
| 89 |
+
if hasattr(model, "module"):
|
| 90 |
+
model = model.module # unwrap DDP model to enable accessing model func directly
|
| 91 |
+
|
| 92 |
+
pretrain_state_dict = {k.replace("module.", ""): v for k, v in pretrain_state_dict.items()}
|
| 93 |
+
model.load_state_dict(pretrain_state_dict)
|
| 94 |
+
print(f"Loaded pretrained state_dict from {checkpoint}")
|
| 95 |
+
model.eval()
|
| 96 |
+
self.model = model
|
| 97 |
+
|
| 98 |
+
self.distance_calculator = DistanceCalculator()
|
| 99 |
+
self.p = Pool()
|
| 100 |
+
|
| 101 |
+
self.initialized = True
|
| 102 |
+
|
| 103 |
+
def preprocess(self, data: List):
|
| 104 |
+
from utils.data_utils import canonicalize_smiles, collate_graph_distances, \
|
| 105 |
+
collate_graph_features, G2SBatch, len2idx
|
| 106 |
+
from utils.preprocess_utils import get_graph_features_from_smi
|
| 107 |
+
|
| 108 |
+
# print(data)
|
| 109 |
+
canonical_smiles = [canonicalize_smiles(smi) for smi in data[0]["body"]["smiles"]]
|
| 110 |
+
|
| 111 |
+
# ----------<adapted from preprocess.py>----------
|
| 112 |
+
start = time.time()
|
| 113 |
+
graph_features_and_lengths = self.p.imap(
|
| 114 |
+
get_graph_features_from_smi, enumerate(canonical_smiles)
|
| 115 |
+
)
|
| 116 |
+
graph_features_and_lengths = list(graph_features_and_lengths)
|
| 117 |
+
print(f"Done graph featurization, time: {time.time() - start}. Collating and saving...")
|
| 118 |
+
a_scopes, a_scopes_lens, b_scopes, b_scopes_lens, a_features, a_features_lens, \
|
| 119 |
+
b_features, b_features_lens, a_graphs, b_graphs = zip(*graph_features_and_lengths)
|
| 120 |
+
|
| 121 |
+
a_scopes = np.concatenate(a_scopes, axis=0)
|
| 122 |
+
b_scopes = np.concatenate(b_scopes, axis=0)
|
| 123 |
+
a_features = np.concatenate(a_features, axis=0)
|
| 124 |
+
b_features = np.concatenate(b_features, axis=0)
|
| 125 |
+
a_graphs = np.concatenate(a_graphs, axis=0)
|
| 126 |
+
b_graphs = np.concatenate(b_graphs, axis=0)
|
| 127 |
+
|
| 128 |
+
a_scopes_lens = np.array(a_scopes_lens, dtype=np.int32)
|
| 129 |
+
b_scopes_lens = np.array(b_scopes_lens, dtype=np.int32)
|
| 130 |
+
a_features_lens = np.array(a_features_lens, dtype=np.int32)
|
| 131 |
+
b_features_lens = np.array(b_features_lens, dtype=np.int32)
|
| 132 |
+
# ----------</adapted from preprocess.py>----------
|
| 133 |
+
|
| 134 |
+
# ----------<adapted from data_utils.G2SDataset.__init__()>----------
|
| 135 |
+
if self.args.mask_rel_chirality == 1:
|
| 136 |
+
a_features[:, 6] = 2
|
| 137 |
+
|
| 138 |
+
a_scopes_indices = len2idx(a_scopes_lens)
|
| 139 |
+
b_scopes_indices = len2idx(b_scopes_lens)
|
| 140 |
+
a_features_indices = len2idx(a_features_lens)
|
| 141 |
+
b_features_indices = len2idx(b_features_lens)
|
| 142 |
+
|
| 143 |
+
del a_scopes_lens, b_scopes_lens, a_features_lens, b_features_lens
|
| 144 |
+
# ----------</adapted from data_utils.G2SDataset.__init__()>----------
|
| 145 |
+
|
| 146 |
+
# ----------<adapted from data_utils.G2SDataset.batch()>----------
|
| 147 |
+
# batching takes trivial time
|
| 148 |
+
batch_sizes = []
|
| 149 |
+
|
| 150 |
+
sample_size = 0
|
| 151 |
+
max_batch_src_len = 0
|
| 152 |
+
|
| 153 |
+
for smi in canonical_smiles:
|
| 154 |
+
src_len = len(smi)
|
| 155 |
+
max_batch_src_len = max(src_len, max_batch_src_len)
|
| 156 |
+
if max_batch_src_len * (sample_size + 1) <= self.args.predict_batch_size:
|
| 157 |
+
sample_size += 1
|
| 158 |
+
else:
|
| 159 |
+
batch_sizes.append(sample_size)
|
| 160 |
+
sample_size = 1
|
| 161 |
+
max_batch_src_len = src_len
|
| 162 |
+
|
| 163 |
+
# lastly
|
| 164 |
+
batch_sizes.append(sample_size)
|
| 165 |
+
batch_sizes = np.array(batch_sizes)
|
| 166 |
+
assert np.sum(batch_sizes) == len(canonical_smiles), \
|
| 167 |
+
f"Size mismatch! Data size: {len(canonical_smiles)}, sum batch sizes: {np.sum(batch_sizes)}"
|
| 168 |
+
|
| 169 |
+
batch_ends = np.cumsum(batch_sizes)
|
| 170 |
+
batch_starts = np.concatenate([[0], batch_ends[:-1]])
|
| 171 |
+
# ----------</adapted from data_utils.G2SDataset.batch()>----------
|
| 172 |
+
|
| 173 |
+
# ----------<adapted from data_utils.G2SDataset.__getitem__()>----------
|
| 174 |
+
g2s_batches = []
|
| 175 |
+
for batch_start, batch_end in zip(batch_starts, batch_ends):
|
| 176 |
+
data_indices = np.arange(batch_start, batch_end)
|
| 177 |
+
graph_features = []
|
| 178 |
+
a_lengths = []
|
| 179 |
+
for data_index in data_indices:
|
| 180 |
+
start, end = a_scopes_indices[data_index]
|
| 181 |
+
a_scope = a_scopes[start:end]
|
| 182 |
+
a_length = a_scope[-1][0] + a_scope[-1][1] - a_scope[0][0]
|
| 183 |
+
|
| 184 |
+
start, end = b_scopes_indices[data_index]
|
| 185 |
+
b_scope = b_scopes[start:end]
|
| 186 |
+
|
| 187 |
+
start, end = a_features_indices[data_index]
|
| 188 |
+
a_feature = a_features[start:end]
|
| 189 |
+
a_graph = a_graphs[start:end]
|
| 190 |
+
|
| 191 |
+
start, end = b_features_indices[data_index]
|
| 192 |
+
b_feature = b_features[start:end]
|
| 193 |
+
b_graph = b_graphs[start:end]
|
| 194 |
+
|
| 195 |
+
graph_feature = (a_scope, b_scope, a_feature, b_feature, a_graph, b_graph)
|
| 196 |
+
graph_features.append(graph_feature)
|
| 197 |
+
a_lengths.append(a_length)
|
| 198 |
+
|
| 199 |
+
fnode, fmess, agraph, bgraph, atom_scope, bond_scope = collate_graph_features(graph_features)
|
| 200 |
+
distances = collate_graph_distances(self.args, graph_features, a_lengths, self.distance_calculator)
|
| 201 |
+
|
| 202 |
+
g2s_batch = G2SBatch(
|
| 203 |
+
fnode=fnode,
|
| 204 |
+
fmess=fmess,
|
| 205 |
+
agraph=agraph,
|
| 206 |
+
bgraph=bgraph,
|
| 207 |
+
atom_scope=atom_scope,
|
| 208 |
+
bond_scope=bond_scope,
|
| 209 |
+
tgt_token_ids=torch.tensor([0]),
|
| 210 |
+
tgt_lengths=torch.tensor(a_lengths),
|
| 211 |
+
distances=distances
|
| 212 |
+
)
|
| 213 |
+
g2s_batches.append(g2s_batch)
|
| 214 |
+
# ----------</adapted from data_utils.G2SDataset.__getitem__()>----------
|
| 215 |
+
|
| 216 |
+
return g2s_batches
|
| 217 |
+
|
| 218 |
+
def inference(self, input, data: List) -> List[Dict[str, Any]]:
|
| 219 |
+
# adapted from predict.get_predictions()
|
| 220 |
+
|
| 221 |
+
from utils.data_utils import canonicalize_smiles
|
| 222 |
+
canonical_smiles = [canonicalize_smiles(smi) for smi in input[0]["body"]["smiles"]]
|
| 223 |
+
|
| 224 |
+
results = []
|
| 225 |
+
|
| 226 |
+
with torch.no_grad():
|
| 227 |
+
for test_idx, test_batch in enumerate(data):
|
| 228 |
+
test_batch.to(self.device)
|
| 229 |
+
batch_predictions = self.model.predict_step(
|
| 230 |
+
reaction_batch=test_batch,
|
| 231 |
+
batch_size=test_batch.size,
|
| 232 |
+
beam_size=self.args.beam_size,
|
| 233 |
+
n_best=self.args.n_best,
|
| 234 |
+
temperature=self.args.temperature,
|
| 235 |
+
min_length=self.args.predict_min_len,
|
| 236 |
+
max_length=self.args.predict_max_len
|
| 237 |
+
)
|
| 238 |
+
|
| 239 |
+
for target, predictions, scores in zip(canonical_smiles, batch_predictions["predictions"], batch_predictions["scores"]):
|
| 240 |
+
valid_product_scores = {}
|
| 241 |
+
for prediction, score in zip(predictions, scores):
|
| 242 |
+
predicted_idx = prediction.detach().cpu().numpy()
|
| 243 |
+
score = score.item()
|
| 244 |
+
predicted_tokens = [self.vocab_tokens[idx] for idx in predicted_idx[:-1]]
|
| 245 |
+
smi = "".join(predicted_tokens)
|
| 246 |
+
product = canonicalize_smiles(smi, trim=False, suppress_warning=True)
|
| 247 |
+
if not product:
|
| 248 |
+
continue
|
| 249 |
+
else:
|
| 250 |
+
if Chem.MolFromSmiles(target).GetNumAtoms() - Chem.MolFromSmiles(product).GetNumAtoms() > 4:
|
| 251 |
+
continue
|
| 252 |
+
if valid_product_scores.get(product) is None:
|
| 253 |
+
valid_product_scores[product] = np.exp(score)
|
| 254 |
+
else:
|
| 255 |
+
valid_product_scores[product] += np.exp(score)
|
| 256 |
+
valid_product_scores = dict(sorted(valid_product_scores.items(), key=lambda x: x[1], reverse=True))
|
| 257 |
+
valid_products = list(valid_product_scores.keys())
|
| 258 |
+
valid_scores = list(valid_product_scores.values())
|
| 259 |
+
result = {
|
| 260 |
+
"products": valid_products,
|
| 261 |
+
"scores": valid_scores
|
| 262 |
+
}
|
| 263 |
+
results.append(result)
|
| 264 |
+
|
| 265 |
+
return results
|
| 266 |
+
|
| 267 |
+
def postprocess(self, data: List[Dict[str, Any]]) -> List[List[Dict[str, Any]]]:
|
| 268 |
+
return [data]
|
| 269 |
+
|
| 270 |
+
def handle(self, data, context) -> List[List[Dict[str, Any]]]:
|
| 271 |
+
self._context = context
|
| 272 |
+
|
| 273 |
+
output = self.preprocess(data)
|
| 274 |
+
output = self.inference(data, output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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import datetime
|
| 3 |
+
import glob
|
| 4 |
+
import numpy as np
|
| 5 |
+
import os
|
| 6 |
+
import sys
|
| 7 |
+
import time
|
| 8 |
+
import torch
|
| 9 |
+
import torch.distributed as dist
|
| 10 |
+
from models.graph2smiles import Graph2SMILES
|
| 11 |
+
from torch.utils.data import DataLoader, SequentialSampler
|
| 12 |
+
from torch.utils.data.distributed import DistributedSampler
|
| 13 |
+
from train import get_model
|
| 14 |
+
from utils import parsing
|
| 15 |
+
from utils.data_utils import canonicalize_smiles, load_vocab, G2SDataset
|
| 16 |
+
from utils.train_utils import log_tensor, log_rank_0, param_count, set_seed, setup_logger
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def get_predict_parser():
|
| 20 |
+
parser = argparse.ArgumentParser("predict")
|
| 21 |
+
parsing.add_common_args(parser)
|
| 22 |
+
parsing.add_preprocess_args(parser)
|
| 23 |
+
parsing.add_train_args(parser)
|
| 24 |
+
parsing.add_predict_args(parser)
|
| 25 |
+
|
| 26 |
+
return parser
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def get_predictions(args, model, vocab_tokens, test_loader, device, start, multiplier=1):
|
| 30 |
+
all_predictions = []
|
| 31 |
+
|
| 32 |
+
log_rank_0(f"nbest = {(args.n_best * multiplier)}")
|
| 33 |
+
|
| 34 |
+
with torch.no_grad():
|
| 35 |
+
for test_idx, test_batch in enumerate(test_loader):
|
| 36 |
+
if test_idx % args.log_iter == 0:
|
| 37 |
+
log_rank_0(f"Doing inference on test step {test_idx}, "
|
| 38 |
+
f"time: {time.time() - start: .2f} s")
|
| 39 |
+
|
| 40 |
+
test_batch.to(device)
|
| 41 |
+
results = model.predict_step(
|
| 42 |
+
reaction_batch=test_batch,
|
| 43 |
+
batch_size=test_batch.size,
|
| 44 |
+
beam_size=args.beam_size,
|
| 45 |
+
n_best=args.n_best * multiplier,
|
| 46 |
+
temperature=args.temperature,
|
| 47 |
+
min_length=args.predict_min_len,
|
| 48 |
+
max_length=args.predict_max_len
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
for predictions, scores in zip(results["predictions"], results["scores"]):
|
| 52 |
+
smis_with_scores = []
|
| 53 |
+
for prediction, score in zip(predictions, scores):
|
| 54 |
+
predicted_idx = prediction.detach().cpu().numpy()
|
| 55 |
+
score = score.detach().cpu().numpy()
|
| 56 |
+
predicted_tokens = [vocab_tokens[idx] for idx in predicted_idx[:-1]]
|
| 57 |
+
smi = "".join(predicted_tokens)
|
| 58 |
+
smis_with_scores.append(f"{smi}_{score}")
|
| 59 |
+
smis_with_scores = ",".join(smis_with_scores)
|
| 60 |
+
all_predictions.append(f"{smis_with_scores}\n")
|
| 61 |
+
|
| 62 |
+
return all_predictions
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def main(args):
|
| 66 |
+
args.device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
| 67 |
+
device = args.device
|
| 68 |
+
if args.local_rank != -1:
|
| 69 |
+
dist.init_process_group(backend=args.backend, init_method='env://', timeout=datetime.timedelta(0, 7200))
|
| 70 |
+
torch.cuda.set_device(args.local_rank)
|
| 71 |
+
torch.backends.cudnn.benchmark = True
|
| 72 |
+
|
| 73 |
+
if torch.distributed.is_initialized():
|
| 74 |
+
log_rank_0(f"Device rank: {torch.distributed.get_rank()}")
|
| 75 |
+
os.makedirs(os.path.join("./results", args.data_name), exist_ok=True)
|
| 76 |
+
# os.makedirs(os.path.join("./results", args.test_output_path), exist_ok=True)
|
| 77 |
+
|
| 78 |
+
parsing.log_args(args, phase="prediction")
|
| 79 |
+
|
| 80 |
+
# initialization ---------------------------------- ckpt parsing
|
| 81 |
+
if args.do_validate:
|
| 82 |
+
checkpoints = glob.glob(os.path.join(args.load_from, "*.pt"))
|
| 83 |
+
checkpoints = sorted(
|
| 84 |
+
checkpoints,
|
| 85 |
+
key=lambda ckpt: int(ckpt.split(".")[-2].split("_")[-1]),
|
| 86 |
+
reverse=True
|
| 87 |
+
)
|
| 88 |
+
multipliers = [3] * len(checkpoints)
|
| 89 |
+
checkpoints = [ckpt for ckpt in checkpoints
|
| 90 |
+
if (args.checkpoint_step_start <= int(ckpt.split(".")[-2].split("_")[1]))
|
| 91 |
+
and (args.checkpoint_step_end >= int(ckpt.split(".")[-2].split("_")[1]))]
|
| 92 |
+
file_bin = os.path.join(args.processed_data_path, "val.npz")
|
| 93 |
+
file_tgt = os.path.join(args.processed_data_path, "tgt-val.txt")
|
| 94 |
+
elif args.do_predict:
|
| 95 |
+
# multipliers = [1, 3, 5, 10, 20]
|
| 96 |
+
multipliers = [3]
|
| 97 |
+
checkpoints = [os.path.join(args.model_path, args.load_from)]
|
| 98 |
+
file_bin = os.path.join(args.processed_data_path, "test.npz")
|
| 99 |
+
file_tgt = os.path.join(args.processed_data_path, "tgt-test.txt")
|
| 100 |
+
else:
|
| 101 |
+
raise ValueError("Either --do_validate or --do_predict need to be specified!")
|
| 102 |
+
|
| 103 |
+
model = None
|
| 104 |
+
test_dataset = None
|
| 105 |
+
vocab_tokens = None
|
| 106 |
+
smis_tgt = []
|
| 107 |
+
start = time.time()
|
| 108 |
+
for ckpt_i, checkpoint in enumerate(checkpoints):
|
| 109 |
+
result_file = os.path.join(args.test_output_path, f"result.{ckpt_i}")
|
| 110 |
+
result_stat_file = os.path.join(args.test_output_path, f"result.stat.{ckpt_i}")
|
| 111 |
+
|
| 112 |
+
if os.path.exists(result_file) and False:
|
| 113 |
+
log_rank_0(f"Result file found at {result_file}, skipping prediction.")
|
| 114 |
+
else:
|
| 115 |
+
log_rank_0(f"Loading from {checkpoint}")
|
| 116 |
+
try:
|
| 117 |
+
state = torch.load(checkpoint)
|
| 118 |
+
except RuntimeError:
|
| 119 |
+
log_rank_0(f"Error loading {checkpoint}, skipping")
|
| 120 |
+
continue # some weird corrupted files
|
| 121 |
+
|
| 122 |
+
pretrain_args = state["args"]
|
| 123 |
+
pretrain_args.load_from = None
|
| 124 |
+
pretrain_state_dict = state["state_dict"]
|
| 125 |
+
pretrain_args.local_rank = args.local_rank
|
| 126 |
+
if not hasattr(pretrain_args, "n_latent"):
|
| 127 |
+
pretrain_args.n_latent = 1
|
| 128 |
+
args.n_latent = pretrain_args.n_latent
|
| 129 |
+
if not hasattr(pretrain_args, "shared_attention_layer"):
|
| 130 |
+
pretrain_args.shared_attention_layer = 0
|
| 131 |
+
|
| 132 |
+
if model is None:
|
| 133 |
+
# initialization ---------------------------------- model
|
| 134 |
+
log_rank_0("Model is None, building model")
|
| 135 |
+
log_rank_0("First logging args for training")
|
| 136 |
+
parsing.log_args(pretrain_args, phase="training")
|
| 137 |
+
|
| 138 |
+
# backward
|
| 139 |
+
assert args.model == pretrain_args.model or \
|
| 140 |
+
pretrain_args.model == "g2s_series_rel", \
|
| 141 |
+
f"Pretrained model is {pretrain_args.model}!"
|
| 142 |
+
model_class = Graph2SMILES
|
| 143 |
+
dataset_class = G2SDataset
|
| 144 |
+
args.compute_graph_distance = True
|
| 145 |
+
|
| 146 |
+
# initialization ---------------------------------- vocab
|
| 147 |
+
vocab = load_vocab(args)
|
| 148 |
+
vocab_tokens = [k for k, v in sorted(vocab.items(), key=lambda tup: tup[1])]
|
| 149 |
+
|
| 150 |
+
model, state = get_model(pretrain_args, model_class, vocab, device)
|
| 151 |
+
if hasattr(model, "module"):
|
| 152 |
+
model = model.module # unwrap DDP model to enable accessing model func directly
|
| 153 |
+
|
| 154 |
+
log_rank_0(model)
|
| 155 |
+
log_rank_0(f"Number of parameters = {param_count(model)}")
|
| 156 |
+
|
| 157 |
+
# initialization ---------------------------------- data
|
| 158 |
+
test_dataset = dataset_class(args, file=file_bin)
|
| 159 |
+
test_dataset.batch(
|
| 160 |
+
batch_type=args.batch_type,
|
| 161 |
+
batch_size=args.predict_batch_size
|
| 162 |
+
)
|
| 163 |
+
with open(file_tgt, "r") as f:
|
| 164 |
+
total = sum(1 for _ in f)
|
| 165 |
+
|
| 166 |
+
with open(file_tgt, "r") as f:
|
| 167 |
+
for line_tgt in f:
|
| 168 |
+
smi_tgt = "".join(line_tgt.split())
|
| 169 |
+
smi_tgt = canonicalize_smiles(smi_tgt)
|
| 170 |
+
smis_tgt.append(smi_tgt)
|
| 171 |
+
|
| 172 |
+
pretrain_state_dict = {k.replace("module.", ""): v for k, v in pretrain_state_dict.items()}
|
| 173 |
+
model.load_state_dict(pretrain_state_dict)
|
| 174 |
+
log_rank_0(f"Loaded pretrained state_dict from {checkpoint}")
|
| 175 |
+
model.eval()
|
| 176 |
+
|
| 177 |
+
if args.local_rank != -1:
|
| 178 |
+
test_sampler = DistributedSampler(test_dataset, shuffle=False)
|
| 179 |
+
else:
|
| 180 |
+
test_sampler = SequentialSampler(test_dataset)
|
| 181 |
+
|
| 182 |
+
test_loader = DataLoader(
|
| 183 |
+
dataset=test_dataset,
|
| 184 |
+
batch_size=1,
|
| 185 |
+
sampler=test_sampler,
|
| 186 |
+
num_workers=args.num_cores,
|
| 187 |
+
collate_fn=lambda _batch: _batch[0],
|
| 188 |
+
pin_memory=True
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
multiplier = multipliers[ckpt_i]
|
| 192 |
+
all_predictions = get_predictions(
|
| 193 |
+
args, model, vocab_tokens, test_loader, device, start, multiplier)
|
| 194 |
+
|
| 195 |
+
if args.local_rank > 0:
|
| 196 |
+
continue
|
| 197 |
+
|
| 198 |
+
# saving prediction results
|
| 199 |
+
with open(result_file, "w") as of:
|
| 200 |
+
of.writelines(all_predictions)
|
| 201 |
+
|
| 202 |
+
if args.do_score:
|
| 203 |
+
if os.path.exists(result_stat_file) and False:
|
| 204 |
+
log_rank_0(f"Result stat file found at {result_stat_file}, skipping scoring.")
|
| 205 |
+
continue
|
| 206 |
+
|
| 207 |
+
invalid = 0
|
| 208 |
+
accuracies = np.zeros([total, args.n_best], dtype=np.float32)
|
| 209 |
+
|
| 210 |
+
with open(result_file, "r") as f_predict:
|
| 211 |
+
for i, (smi_tgt, line_predict) in enumerate(zip(smis_tgt, f_predict)):
|
| 212 |
+
if smi_tgt == "CC": # problematic SMILES
|
| 213 |
+
continue
|
| 214 |
+
|
| 215 |
+
line_predict = "".join(line_predict.split())
|
| 216 |
+
smis_predict = line_predict.split(",")
|
| 217 |
+
smis_predict = [smi.split("_")[0] for smi in smis_predict]
|
| 218 |
+
smis_predict = [canonicalize_smiles(smi, trim=False, suppress_warning=True) for smi in smis_predict]
|
| 219 |
+
if not smis_predict[0]:
|
| 220 |
+
invalid += 1
|
| 221 |
+
smis_predict = [smi for smi in smis_predict if smi and not smi == "CC"]
|
| 222 |
+
smis_predict = list(dict.fromkeys(smis_predict))
|
| 223 |
+
|
| 224 |
+
for j, smi in enumerate(smis_predict[:args.n_best]):
|
| 225 |
+
if smi == smi_tgt:
|
| 226 |
+
accuracies[i, j:] = 1.0
|
| 227 |
+
break
|
| 228 |
+
|
| 229 |
+
with open(result_stat_file, "w") as of:
|
| 230 |
+
line = f"Total: {total}, top 1 invalid: {invalid / total * 100: .2f} %"
|
| 231 |
+
log_rank_0(line)
|
| 232 |
+
of.write(f"{line}\n")
|
| 233 |
+
|
| 234 |
+
mean_accuracies = np.mean(accuracies, axis=0)
|
| 235 |
+
for n in range(args.n_best):
|
| 236 |
+
line = f"Top {n+1} accuracy: {mean_accuracies[n] * 100: .2f} %"
|
| 237 |
+
log_rank_0(line)
|
| 238 |
+
of.write(f"{line}\n")
|
| 239 |
+
|
| 240 |
+
log_rank_0(f"Elapsed time: {time.time() - start: .2f} s")
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
if __name__ == "__main__":
|
| 244 |
+
# initialization ---------------------------------- args, logs and devices
|
| 245 |
+
predict_parser = get_predict_parser()
|
| 246 |
+
args = predict_parser.parse_args()
|
| 247 |
+
|
| 248 |
+
setup_logger(args, warning_off=True)
|
| 249 |
+
np.set_printoptions(threshold=sys.maxsize)
|
| 250 |
+
torch.set_printoptions(profile="full")
|
| 251 |
+
|
| 252 |
+
set_seed(args.seed)
|
| 253 |
+
|
| 254 |
+
main(args)
|
checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/mar_files/train.py
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import datetime
|
| 3 |
+
import logging
|
| 4 |
+
import numpy as np
|
| 5 |
+
import os
|
| 6 |
+
import sys
|
| 7 |
+
import torch
|
| 8 |
+
import torch.distributed as dist
|
| 9 |
+
import torch.nn as nn
|
| 10 |
+
import torch.optim as optim
|
| 11 |
+
from models.graph2smiles import Graph2SMILES
|
| 12 |
+
import time
|
| 13 |
+
from torch.nn.init import xavier_uniform_
|
| 14 |
+
from torch.nn.parallel import DistributedDataParallel as DDP
|
| 15 |
+
from torch.utils.data import DataLoader, RandomSampler, SequentialSampler
|
| 16 |
+
from torch.utils.data.distributed import DistributedSampler
|
| 17 |
+
from typing import Dict
|
| 18 |
+
from utils import parsing
|
| 19 |
+
from utils.data_utils import G2SDataset
|
| 20 |
+
from utils.preprocess_utils import load_vocab
|
| 21 |
+
from utils.train_utils import get_lr, grad_norm, log_rank_0, NoamLR, \
|
| 22 |
+
param_count, param_norm, set_seed, setup_logger
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def get_train_parser():
|
| 26 |
+
parser = argparse.ArgumentParser("train")
|
| 27 |
+
parsing.add_common_args(parser)
|
| 28 |
+
parsing.add_train_args(parser)
|
| 29 |
+
parsing.add_predict_args(parser)
|
| 30 |
+
|
| 31 |
+
return parser
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def init_dist(args):
|
| 35 |
+
if args.local_rank != -1:
|
| 36 |
+
dist.init_process_group(backend=args.backend,
|
| 37 |
+
init_method='env://',
|
| 38 |
+
timeout=datetime.timedelta(0, 7200))
|
| 39 |
+
torch.cuda.set_device(args.local_rank)
|
| 40 |
+
torch.backends.cudnn.benchmark = False
|
| 41 |
+
|
| 42 |
+
if dist.is_initialized():
|
| 43 |
+
logging.info(f"Device rank: {dist.get_rank()}")
|
| 44 |
+
sys.stdout.flush()
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def get_model(args, model_class, vocab: Dict[str, int], device):
|
| 48 |
+
state = {}
|
| 49 |
+
if args.load_from:
|
| 50 |
+
log_rank_0(f"Loading pretrained state from {args.load_from}")
|
| 51 |
+
state = torch.load(args.load_from, map_location=torch.device("cpu"))
|
| 52 |
+
pretrain_args = state["args"]
|
| 53 |
+
pretrain_args.local_rank = args.local_rank
|
| 54 |
+
parsing.log_args(pretrain_args, phase="pretraining")
|
| 55 |
+
|
| 56 |
+
model = model_class(pretrain_args, vocab)
|
| 57 |
+
pretrain_state_dict = state["state_dict"]
|
| 58 |
+
pretrain_state_dict = {k.replace("module.", ""): v for k, v in pretrain_state_dict.items()}
|
| 59 |
+
model.load_state_dict(pretrain_state_dict)
|
| 60 |
+
log_rank_0("Loaded pretrained model state_dict.")
|
| 61 |
+
else:
|
| 62 |
+
model = model_class(args, vocab)
|
| 63 |
+
for p in model.parameters():
|
| 64 |
+
if p.dim() > 1 and p.requires_grad:
|
| 65 |
+
xavier_uniform_(p)
|
| 66 |
+
|
| 67 |
+
model.to(device)
|
| 68 |
+
if args.local_rank != -1:
|
| 69 |
+
model = DDP(
|
| 70 |
+
model,
|
| 71 |
+
device_ids=[args.local_rank],
|
| 72 |
+
output_device=args.local_rank
|
| 73 |
+
)
|
| 74 |
+
log_rank_0("DDP setup finished")
|
| 75 |
+
|
| 76 |
+
return model, state
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def get_optimizer_and_scheduler(args, model, state):
|
| 80 |
+
optimizer = optim.AdamW(
|
| 81 |
+
model.parameters(),
|
| 82 |
+
lr=args.lr,
|
| 83 |
+
betas=(args.beta1, args.beta2),
|
| 84 |
+
eps=args.eps,
|
| 85 |
+
weight_decay=args.weight_decay
|
| 86 |
+
)
|
| 87 |
+
scheduler = NoamLR(
|
| 88 |
+
optimizer,
|
| 89 |
+
model_size=args.decoder_hidden_size,
|
| 90 |
+
warmup_steps=args.warmup_steps
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
if state and args.resume:
|
| 94 |
+
optimizer.load_state_dict(state["optimizer"])
|
| 95 |
+
scheduler.load_state_dict(state["scheduler"])
|
| 96 |
+
log_rank_0("Loaded pretrained optimizer and scheduler state_dicts.")
|
| 97 |
+
|
| 98 |
+
return optimizer, scheduler
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def init_loader(args, dataset, batch_size: int, bucket_size: int = 1000,
|
| 102 |
+
shuffle: bool = False, epoch: int = None):
|
| 103 |
+
dataset.sort()
|
| 104 |
+
dataset.shuffle_in_bucket(bucket_size=bucket_size)
|
| 105 |
+
dataset.batch(
|
| 106 |
+
batch_type=args.batch_type,
|
| 107 |
+
batch_size=batch_size
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
if args.local_rank != -1:
|
| 111 |
+
sampler = DistributedSampler(dataset, shuffle=shuffle)
|
| 112 |
+
if epoch is not None:
|
| 113 |
+
sampler.set_epoch(epoch)
|
| 114 |
+
else:
|
| 115 |
+
sampler = RandomSampler(dataset) if shuffle else SequentialSampler(dataset)
|
| 116 |
+
|
| 117 |
+
loader = DataLoader(
|
| 118 |
+
dataset=dataset,
|
| 119 |
+
batch_size=1,
|
| 120 |
+
sampler=sampler,
|
| 121 |
+
num_workers=args.num_cores,
|
| 122 |
+
collate_fn=lambda _batch: _batch[0],
|
| 123 |
+
pin_memory=True
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
return loader
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def _optimize(args, model, optimizer, scheduler, accum_count):
|
| 130 |
+
# for param in model.parameters():
|
| 131 |
+
# param.grad /= accum_count
|
| 132 |
+
|
| 133 |
+
nn.utils.clip_grad_norm_(model.parameters(), args.clip_norm)
|
| 134 |
+
optimizer.step()
|
| 135 |
+
scheduler.step()
|
| 136 |
+
g_norm = grad_norm(model)
|
| 137 |
+
model.zero_grad(set_to_none=True)
|
| 138 |
+
|
| 139 |
+
return g_norm
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def train_main(args):
|
| 143 |
+
args.device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
| 144 |
+
device = args.device
|
| 145 |
+
|
| 146 |
+
init_dist(args)
|
| 147 |
+
parsing.log_args(args, phase="training")
|
| 148 |
+
|
| 149 |
+
vocab_file = os.path.join(args.processed_data_path, "vocab.txt")
|
| 150 |
+
if not os.path.exists(vocab_file):
|
| 151 |
+
raise ValueError(f"Vocab file {vocab_file} not found!")
|
| 152 |
+
vocab = load_vocab(args)
|
| 153 |
+
|
| 154 |
+
os.makedirs(args.model_path, exist_ok=True)
|
| 155 |
+
model_class = Graph2SMILES
|
| 156 |
+
dataset_class = G2SDataset
|
| 157 |
+
assert args.compute_graph_distance
|
| 158 |
+
|
| 159 |
+
model, state = get_model(args, model_class, vocab, device)
|
| 160 |
+
log_rank_0(model)
|
| 161 |
+
log_rank_0(f"Number of parameters = {param_count(model)}")
|
| 162 |
+
|
| 163 |
+
optimizer, scheduler = get_optimizer_and_scheduler(args, model, state)
|
| 164 |
+
|
| 165 |
+
train_bin = os.path.join(args.processed_data_path, "train.npz")
|
| 166 |
+
val_bin = os.path.join(args.processed_data_path, "val.npz")
|
| 167 |
+
|
| 168 |
+
train_dataset = dataset_class(args, file=train_bin)
|
| 169 |
+
val_dataset = dataset_class(args, file=val_bin)
|
| 170 |
+
|
| 171 |
+
total_step = state["total_step"] if state else 0
|
| 172 |
+
accum = 0
|
| 173 |
+
g_norm = 0
|
| 174 |
+
losses, accs, ems = [], [], []
|
| 175 |
+
o_start = time.time()
|
| 176 |
+
log_rank_0("Start training")
|
| 177 |
+
|
| 178 |
+
for epoch in range(args.epoch):
|
| 179 |
+
model.train()
|
| 180 |
+
model.zero_grad(set_to_none=True)
|
| 181 |
+
train_loader = init_loader(args, train_dataset,
|
| 182 |
+
batch_size=args.train_batch_size,
|
| 183 |
+
shuffle=True,
|
| 184 |
+
epoch=epoch)
|
| 185 |
+
for batch_idx, train_batch in enumerate(train_loader):
|
| 186 |
+
|
| 187 |
+
if train_batch is None:
|
| 188 |
+
log_rank_0("Fail distance compute, too large due to node size")
|
| 189 |
+
continue
|
| 190 |
+
|
| 191 |
+
if total_step > args.max_steps:
|
| 192 |
+
log_rank_0("Max steps reached, finish training")
|
| 193 |
+
exit(0)
|
| 194 |
+
train_batch.to(device)
|
| 195 |
+
batch_losses, acc, em = model(train_batch)
|
| 196 |
+
loss = batch_losses.mean()
|
| 197 |
+
(loss / args.accumulation_count).backward() # average out the loss over multiple batches during accumulation
|
| 198 |
+
losses.append(loss.item())
|
| 199 |
+
accs.append(acc.item() * 100)
|
| 200 |
+
ems.append(em.item() * 100)
|
| 201 |
+
|
| 202 |
+
accum += 1
|
| 203 |
+
if accum == args.accumulation_count:
|
| 204 |
+
g_norm = _optimize(args, model, optimizer, scheduler, args.accumulation_count)
|
| 205 |
+
accum = 0
|
| 206 |
+
total_step += 1
|
| 207 |
+
|
| 208 |
+
if (accum == 0) and (total_step > 0) and (total_step % args.log_iter == 0):
|
| 209 |
+
log_rank_0(f"Step {total_step}, loss: {np.mean(losses)}, "
|
| 210 |
+
f"acc: {np.mean(accs): .4f}, em: {np.mean(ems): .4f}, "
|
| 211 |
+
f"p_norm: {param_norm(model): .4f}, g_norm: {g_norm: .4f}, "
|
| 212 |
+
f"lr: {get_lr(optimizer): .6f}, "
|
| 213 |
+
f"elapsed time: {time.time() - o_start: .0f}")
|
| 214 |
+
losses, accs, ems = [], [], []
|
| 215 |
+
|
| 216 |
+
if (accum == 0) and (total_step > 0) and (total_step % args.eval_iter == 0):
|
| 217 |
+
model.eval()
|
| 218 |
+
val_count = 100
|
| 219 |
+
val_losses, val_accs, val_ems = [], [], []
|
| 220 |
+
|
| 221 |
+
val_loader = init_loader(args, val_dataset,
|
| 222 |
+
batch_size=args.val_batch_size,
|
| 223 |
+
shuffle=True,
|
| 224 |
+
epoch=None)
|
| 225 |
+
with torch.no_grad():
|
| 226 |
+
for val_idx, val_batch in enumerate(val_loader):
|
| 227 |
+
if val_batch is None:
|
| 228 |
+
log_rank_0("Fail distance compute, too large due to node size")
|
| 229 |
+
continue
|
| 230 |
+
|
| 231 |
+
if val_idx >= val_count:
|
| 232 |
+
break
|
| 233 |
+
val_batch.to(device)
|
| 234 |
+
val_batch_losses, val_acc, val_em = model(val_batch)
|
| 235 |
+
val_loss = val_batch_losses.mean()
|
| 236 |
+
val_losses.append(val_loss.item())
|
| 237 |
+
val_accs.append(val_acc.item() * 100)
|
| 238 |
+
val_ems.append(val_em.item() * 100)
|
| 239 |
+
|
| 240 |
+
log_rank_0(f"Validation (with teacher) at step {total_step}, "
|
| 241 |
+
f"val loss: {np.mean(val_losses)}, "
|
| 242 |
+
f"val acc: {np.mean(val_accs): .4f}, "
|
| 243 |
+
f"val em: {np.mean(val_ems): .4f}")
|
| 244 |
+
model.train()
|
| 245 |
+
|
| 246 |
+
# Important: saving only at one node or the ckpt would be corrupted!
|
| 247 |
+
if dist.is_initialized() and dist.get_rank() > 0:
|
| 248 |
+
continue
|
| 249 |
+
|
| 250 |
+
if (accum == 0) and (total_step > 0) and (total_step % args.save_iter == 0):
|
| 251 |
+
n_iter = total_step // args.save_iter - 1
|
| 252 |
+
log_rank_0(f"Saving at step {total_step}")
|
| 253 |
+
state = {
|
| 254 |
+
"args": args,
|
| 255 |
+
"total_step": total_step,
|
| 256 |
+
"state_dict": model.state_dict(),
|
| 257 |
+
"optimizer": optimizer.state_dict(),
|
| 258 |
+
"scheduler": scheduler.state_dict()
|
| 259 |
+
}
|
| 260 |
+
torch.save(state, os.path.join(args.model_path, f"model.{total_step}_{n_iter}.pt"))
|
| 261 |
+
|
| 262 |
+
# lastly
|
| 263 |
+
if (args.accumulation_count > 1) and (accum > 0):
|
| 264 |
+
g_norm = _optimize(args, model, optimizer, scheduler, args.accumulation_count)
|
| 265 |
+
accum = 0
|
| 266 |
+
# total_step += 1 # for partial batch, do not increase total_step
|
| 267 |
+
|
| 268 |
+
if args.local_rank != -1:
|
| 269 |
+
dist.barrier()
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
if __name__ == "__main__":
|
| 273 |
+
train_parser = get_train_parser()
|
| 274 |
+
args = train_parser.parse_args()
|
| 275 |
+
|
| 276 |
+
# set random seed
|
| 277 |
+
set_seed(args.seed)
|
| 278 |
+
|
| 279 |
+
# logger setup
|
| 280 |
+
logger = setup_logger(args)
|
| 281 |
+
|
| 282 |
+
# maximize display for debugging
|
| 283 |
+
np.set_printoptions(threshold=sys.maxsize)
|
| 284 |
+
torch.set_printoptions(profile="full")
|
| 285 |
+
|
| 286 |
+
args.local_rank = int(os.environ["LOCAL_RANK"]) if os.environ.get("LOCAL_RANK") else -1
|
| 287 |
+
train_main(args)
|
checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/mar_files/vocab.txt
ADDED
|
@@ -0,0 +1,518 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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9640471
|
| 17 |
+
5 812956
|
| 18 |
+
6 234756
|
| 19 |
+
[nH] 841266
|
| 20 |
+
7 74414
|
| 21 |
+
- 2618845
|
| 22 |
+
8 26942
|
| 23 |
+
[C@H] 2113649
|
| 24 |
+
o 525176
|
| 25 |
+
[C@@H] 2151298
|
| 26 |
+
S 1586078
|
| 27 |
+
[N+] 539390
|
| 28 |
+
[O-] 502732
|
| 29 |
+
s 718167
|
| 30 |
+
[C@@] 226220
|
| 31 |
+
F 5392896
|
| 32 |
+
Cl 2694145
|
| 33 |
+
# 870630
|
| 34 |
+
[Si] 364752
|
| 35 |
+
I 249124
|
| 36 |
+
P 154421
|
| 37 |
+
/ 583748
|
| 38 |
+
Br 1230889
|
| 39 |
+
B 290641
|
| 40 |
+
[C@] 256261
|
| 41 |
+
\ 138044
|
| 42 |
+
[2H] 140180
|
| 43 |
+
[N-] 81532
|
| 44 |
+
[Li] 26276
|
| 45 |
+
[Se] 3298
|
| 46 |
+
[S] 2125
|
| 47 |
+
[n+] 25340
|
| 48 |
+
[Na] 91398
|
| 49 |
+
[s+] 267
|
| 50 |
+
[C] 1245
|
| 51 |
+
[S@] 11769
|
| 52 |
+
[S@@] 10494
|
| 53 |
+
[P+] 8009
|
| 54 |
+
[Te] 188
|
| 55 |
+
[S+] 2647
|
| 56 |
+
9 9238
|
| 57 |
+
[CH2] 761
|
| 58 |
+
[K] 59765
|
| 59 |
+
[Zr-2] 22
|
| 60 |
+
[C-] 8025
|
| 61 |
+
[Hf] 106
|
| 62 |
+
[19F] 28
|
| 63 |
+
[18F] 1078
|
| 64 |
+
[Zn] 10227
|
| 65 |
+
[se] 2302
|
| 66 |
+
[Al] 1828
|
| 67 |
+
%10 3146
|
| 68 |
+
[SiH2] 2831
|
| 69 |
+
[Ca] 1528
|
| 70 |
+
[131I] 14
|
| 71 |
+
[PH] 4148
|
| 72 |
+
[Ag] 545
|
| 73 |
+
[Sn] 21897
|
| 74 |
+
[NH] 1491
|
| 75 |
+
[SH] 2131
|
| 76 |
+
[15nH] 17
|
| 77 |
+
[13c] 268
|
| 78 |
+
[Ir] 199
|
| 79 |
+
%11 1922
|
| 80 |
+
%12 1192
|
| 81 |
+
%13 802
|
| 82 |
+
%14 576
|
| 83 |
+
%15 458
|
| 84 |
+
%16 398
|
| 85 |
+
%17 272
|
| 86 |
+
%18 212
|
| 87 |
+
%19 184
|
| 88 |
+
%20 194
|
| 89 |
+
%21 132
|
| 90 |
+
[SiH] 4689
|
| 91 |
+
[Ge] 681
|
| 92 |
+
[NH2+] 3122
|
| 93 |
+
[Fe] 1209
|
| 94 |
+
[K+] 12
|
| 95 |
+
[Mg] 25244
|
| 96 |
+
[Ti] 732
|
| 97 |
+
[Cs] 10834
|
| 98 |
+
[O] 1822
|
| 99 |
+
[B-] 9477
|
| 100 |
+
[c-] 448
|
| 101 |
+
[S@@+] 291
|
| 102 |
+
[P] 1351
|
| 103 |
+
[Pd] 268
|
| 104 |
+
[SiH3] 746
|
| 105 |
+
[n-] 399
|
| 106 |
+
[11CH3] 102
|
| 107 |
+
[125I] 84
|
| 108 |
+
[CH] 554
|
| 109 |
+
[C+] 309
|
| 110 |
+
[NH3+] 4724
|
| 111 |
+
[P@] 1448
|
| 112 |
+
[P-] 52
|
| 113 |
+
[Zr] 210
|
| 114 |
+
[N] 434
|
| 115 |
+
[H] 1058
|
| 116 |
+
[N@] 534
|
| 117 |
+
[NH+] 1930
|
| 118 |
+
%22 116
|
| 119 |
+
%23 88
|
| 120 |
+
%24 82
|
| 121 |
+
[Ru] 356
|
| 122 |
+
[nH+] 2000
|
| 123 |
+
[PH2] 345
|
| 124 |
+
[P@@] 1221
|
| 125 |
+
[YH] 20
|
| 126 |
+
[N@@] 517
|
| 127 |
+
[c+] 45
|
| 128 |
+
[Mn] 1047
|
| 129 |
+
[o+] 238
|
| 130 |
+
[cH-] 259
|
| 131 |
+
[SeH] 168
|
| 132 |
+
[Pt] 183
|
| 133 |
+
[p+] 6
|
| 134 |
+
[99Tc] 2
|
| 135 |
+
[BH] 216
|
| 136 |
+
[S@+] 272
|
| 137 |
+
p 336
|
| 138 |
+
[Cu] 3973
|
| 139 |
+
[211At] 8
|
| 140 |
+
[IrH2] 3
|
| 141 |
+
[pH] 12
|
| 142 |
+
[Pb] 371
|
| 143 |
+
[Si@@H] 275
|
| 144 |
+
[CH+] 63
|
| 145 |
+
[te] 203
|
| 146 |
+
[Tb] 4
|
| 147 |
+
[Co] 173
|
| 148 |
+
[Cl+] 1706
|
| 149 |
+
[S-] 1123
|
| 150 |
+
[In] 74
|
| 151 |
+
[Nb] 40
|
| 152 |
+
[Be] 24
|
| 153 |
+
[B] 377
|
| 154 |
+
[O+] 4734
|
| 155 |
+
[OH2+] 18
|
| 156 |
+
[13C] 303
|
| 157 |
+
%25 64
|
| 158 |
+
[123I] 51
|
| 159 |
+
%26 46
|
| 160 |
+
%27 50
|
| 161 |
+
%28 60
|
| 162 |
+
%29 44
|
| 163 |
+
%30 40
|
| 164 |
+
%31 42
|
| 165 |
+
%32 50
|
| 166 |
+
%33 34
|
| 167 |
+
%34 34
|
| 168 |
+
%35 24
|
| 169 |
+
%36 36
|
| 170 |
+
%37 26
|
| 171 |
+
%38 24
|
| 172 |
+
%39 24
|
| 173 |
+
%40 32
|
| 174 |
+
%41 24
|
| 175 |
+
%42 24
|
| 176 |
+
%43 20
|
| 177 |
+
[W] 36
|
| 178 |
+
[N@+] 44
|
| 179 |
+
[13CH2] 127
|
| 180 |
+
[Sc] 7
|
| 181 |
+
[As] 203
|
| 182 |
+
[SiH4] 40
|
| 183 |
+
[14c] 17
|
| 184 |
+
[AlH] 875
|
| 185 |
+
[Na+] 97
|
| 186 |
+
[CH-] 208
|
| 187 |
+
[OH+] 108
|
| 188 |
+
[SH2] 78
|
| 189 |
+
[Zn+2] 36
|
| 190 |
+
[68Ga] 2
|
| 191 |
+
[Hg] 131
|
| 192 |
+
[Cr] 1600
|
| 193 |
+
[Ni] 173
|
| 194 |
+
[Sb] 127
|
| 195 |
+
[13cH] 109
|
| 196 |
+
[CH2-] 295
|
| 197 |
+
[Ta] 25
|
| 198 |
+
[I+] 272
|
| 199 |
+
[Lu] 23
|
| 200 |
+
[Sr] 11
|
| 201 |
+
[Si@] 154
|
| 202 |
+
[Si@@] 151
|
| 203 |
+
[Mo] 206
|
| 204 |
+
[siH] 14
|
| 205 |
+
[15NH2] 49
|
| 206 |
+
[11c] 1
|
| 207 |
+
[TeH] 40
|
| 208 |
+
[I-] 15
|
| 209 |
+
[Ga] 37
|
| 210 |
+
[Gd] 8
|
| 211 |
+
[Tc] 3
|
| 212 |
+
[Pr] 2
|
| 213 |
+
[GeH3] 7
|
| 214 |
+
[124I] 15
|
| 215 |
+
[13CH3] 151
|
| 216 |
+
[15N] 18
|
| 217 |
+
[NH-] 495
|
| 218 |
+
[CH2+] 172
|
| 219 |
+
[H+] 145
|
| 220 |
+
[I+2] 20
|
| 221 |
+
[P@@H] 2
|
| 222 |
+
[64Cu] 1
|
| 223 |
+
[14C] 59
|
| 224 |
+
[Li+] 9
|
| 225 |
+
[La] 108
|
| 226 |
+
[TeH3] 4
|
| 227 |
+
[SbH2] 4
|
| 228 |
+
[Bi] 270
|
| 229 |
+
[BH3-] 1781
|
| 230 |
+
[13CH] 22
|
| 231 |
+
[B@@-] 4
|
| 232 |
+
[15N+] 7
|
| 233 |
+
[15NH] 22
|
| 234 |
+
[15OH] 1
|
| 235 |
+
[Ne] 5
|
| 236 |
+
[Ba] 21
|
| 237 |
+
[Au] 121
|
| 238 |
+
[Fm] 10
|
| 239 |
+
[Eu] 17
|
| 240 |
+
[Si@H] 67
|
| 241 |
+
[14CH] 23
|
| 242 |
+
[GeH2] 3
|
| 243 |
+
[c] 15
|
| 244 |
+
[N@@+] 25
|
| 245 |
+
[S+2] 74
|
| 246 |
+
[Th] 4
|
| 247 |
+
[SnH2] 30
|
| 248 |
+
[SnH] 333
|
| 249 |
+
[11C] 9
|
| 250 |
+
[InH2] 18
|
| 251 |
+
[U] 2
|
| 252 |
+
[As+] 5
|
| 253 |
+
b 22
|
| 254 |
+
[Ag+] 41
|
| 255 |
+
[14cH] 4
|
| 256 |
+
[SH+] 58
|
| 257 |
+
[Rh] 31
|
| 258 |
+
[IH] 38
|
| 259 |
+
[Os] 12
|
| 260 |
+
[Gd+3] 34
|
| 261 |
+
[3H] 178
|
| 262 |
+
[cH+] 61
|
| 263 |
+
[Ce] 60
|
| 264 |
+
[B@-] 8
|
| 265 |
+
[SnH3] 80
|
| 266 |
+
[Re] 12
|
| 267 |
+
[PH+] 248
|
| 268 |
+
[15NH2+] 2
|
| 269 |
+
[AsH2] 4
|
| 270 |
+
[18O] 23
|
| 271 |
+
[Sn+2] 10
|
| 272 |
+
[I+3] 867
|
| 273 |
+
[13C-] 2
|
| 274 |
+
[Mg+] 5
|
| 275 |
+
[Cl+2] 20
|
| 276 |
+
[10B] 7
|
| 277 |
+
[TaH3] 3
|
| 278 |
+
[NiH] 3
|
| 279 |
+
[15n] 18
|
| 280 |
+
[113C] 2
|
| 281 |
+
[CH3+] 37
|
| 282 |
+
[se+] 16
|
| 283 |
+
[IrH] 9
|
| 284 |
+
[Au-] 3
|
| 285 |
+
[TiH] 5
|
| 286 |
+
[14CH3] 24
|
| 287 |
+
[V] 17
|
| 288 |
+
[Fe+2] 116
|
| 289 |
+
[Cl+3] 268
|
| 290 |
+
[AsH] 10
|
| 291 |
+
[32P] 8
|
| 292 |
+
[SH4] 5
|
| 293 |
+
[Mn+2] 2
|
| 294 |
+
[F-] 2223
|
| 295 |
+
[13C@@H] 3
|
| 296 |
+
[GeH] 12
|
| 297 |
+
[N@H+] 6
|
| 298 |
+
[ZrH2] 1
|
| 299 |
+
[Cu+] 8
|
| 300 |
+
[F+] 7
|
| 301 |
+
[14C@@H] 2
|
| 302 |
+
[3Si] 2
|
| 303 |
+
[Rh+] 1
|
| 304 |
+
[P@@+] 1
|
| 305 |
+
%44 8
|
| 306 |
+
%45 8
|
| 307 |
+
%46 8
|
| 308 |
+
%47 8
|
| 309 |
+
%48 4
|
| 310 |
+
%49 4
|
| 311 |
+
[Si-] 33
|
| 312 |
+
[17O] 4
|
| 313 |
+
[Y] 3
|
| 314 |
+
[Po] 2
|
| 315 |
+
[te+] 2
|
| 316 |
+
[si] 5
|
| 317 |
+
[16F] 3
|
| 318 |
+
[79Br] 1
|
| 319 |
+
[Se+] 2
|
| 320 |
+
[CaH] 2
|
| 321 |
+
[177Lu] 2
|
| 322 |
+
[Cu-2] 4
|
| 323 |
+
[13NH2] 1
|
| 324 |
+
[Ho] 4
|
| 325 |
+
[PH4] 8
|
| 326 |
+
[Br+2] 34
|
| 327 |
+
[Cu+2] 77
|
| 328 |
+
[14CH2] 8
|
| 329 |
+
[4He] 1
|
| 330 |
+
[SbH] 2
|
| 331 |
+
[NaH] 1
|
| 332 |
+
[Ar] 19
|
| 333 |
+
[N+2] 3
|
| 334 |
+
[5O] 1
|
| 335 |
+
[N@@H+] 6
|
| 336 |
+
[ClH+] 4
|
| 337 |
+
[Ti+] 1
|
| 338 |
+
[AlH3] 3
|
| 339 |
+
[BH-] 2762
|
| 340 |
+
[Yb] 7
|
| 341 |
+
[Ba+2] 64
|
| 342 |
+
[Cr+] 1
|
| 343 |
+
[He] 3
|
| 344 |
+
[RuH] 8
|
| 345 |
+
[Li-2] 2
|
| 346 |
+
[Dy] 2
|
| 347 |
+
[Si+] 8
|
| 348 |
+
[YH3] 1
|
| 349 |
+
[Co+2] 125
|
| 350 |
+
[Ni+2] 7
|
| 351 |
+
[Sb-] 8
|
| 352 |
+
[Fe+3] 23
|
| 353 |
+
[Zn+] 12
|
| 354 |
+
. 2797764
|
| 355 |
+
[Bi+2] 4
|
| 356 |
+
[Ir+] 2
|
| 357 |
+
[H-] 296
|
| 358 |
+
[AlH2-] 59
|
| 359 |
+
[S-2] 120
|
| 360 |
+
[Eu+3] 2
|
| 361 |
+
[Fe-4] 64
|
| 362 |
+
[AlH-] 19
|
| 363 |
+
[PH4+] 9
|
| 364 |
+
[Fe-3] 30
|
| 365 |
+
[In+3] 2
|
| 366 |
+
* 166
|
| 367 |
+
[Pt-2] 9
|
| 368 |
+
[Al-] 30
|
| 369 |
+
[Cs+] 16
|
| 370 |
+
[Tl+3] 20
|
| 371 |
+
[Sb+5] 7
|
| 372 |
+
[Se-] 6
|
| 373 |
+
[Pb+2] 9
|
| 374 |
+
[Hf+2] 19
|
| 375 |
+
[Yb+3] 37
|
| 376 |
+
[Ce+4] 115
|
| 377 |
+
[PH2+] 10
|
| 378 |
+
[BH4-] 214
|
| 379 |
+
[PH3] 26
|
| 380 |
+
[PH3+] 103
|
| 381 |
+
[AlH4-] 44
|
| 382 |
+
[Al+3] 39
|
| 383 |
+
[Al+] 77
|
| 384 |
+
[CH3-] 98
|
| 385 |
+
[Ti+3] 67
|
| 386 |
+
[AlH4] 8
|
| 387 |
+
[Ti+4] 4
|
| 388 |
+
[Ce+3] 47
|
| 389 |
+
[Tl] 24
|
| 390 |
+
[P+3] 54
|
| 391 |
+
[sH+] 12
|
| 392 |
+
[Tl+] 22
|
| 393 |
+
[SH3+] 2
|
| 394 |
+
[SeH2] 15
|
| 395 |
+
[Sr+2] 4
|
| 396 |
+
[Ti+2] 10
|
| 397 |
+
[SeH-] 8
|
| 398 |
+
[Br+] 26
|
| 399 |
+
[SH2+] 14
|
| 400 |
+
[TeH2] 1
|
| 401 |
+
[F] 2
|
| 402 |
+
[Ga+] 5
|
| 403 |
+
[Ge-] 4
|
| 404 |
+
[Ac-] 2
|
| 405 |
+
[B+] 20
|
| 406 |
+
[Ce+2] 3
|
| 407 |
+
[Bi+3] 16
|
| 408 |
+
[SH-] 40
|
| 409 |
+
[Er+3] 2
|
| 410 |
+
[InH] 4
|
| 411 |
+
[Pd+2] 21
|
| 412 |
+
[Zr+4] 7
|
| 413 |
+
[Zr+2] 8
|
| 414 |
+
[B+3] 5
|
| 415 |
+
[Cu-] 6
|
| 416 |
+
[Cr+3] 9
|
| 417 |
+
[La+3] 9
|
| 418 |
+
[Mn+3] 3
|
| 419 |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|
| 474 |
+
[Se+2] 1
|
| 475 |
+
[oH+] 1
|
| 476 |
+
[p-] 1
|
| 477 |
+
[18OH] 1
|
| 478 |
+
[Co+3] 1
|
| 479 |
+
[Y-] 1
|
| 480 |
+
[C-4] 1
|
| 481 |
+
[2H+] 1
|
| 482 |
+
[3H+] 1
|
| 483 |
+
[BiH3] 1
|
| 484 |
+
[FH+] 1
|
| 485 |
+
[PH-] 4
|
| 486 |
+
[Ge+4] 1
|
| 487 |
+
[AsH3] 1
|
| 488 |
+
[Sm+2] 1
|
| 489 |
+
[As+3] 2
|
| 490 |
+
[Br+3] 1
|
| 491 |
+
[SH3] 1
|
| 492 |
+
[BrH+] 2
|
| 493 |
+
[113CH3] 1
|
| 494 |
+
[Ta+2] 1
|
| 495 |
+
[NH3+2] 2
|
| 496 |
+
[Yb+2] 1
|
| 497 |
+
[Cr+2] 2
|
| 498 |
+
[I] 1
|
| 499 |
+
[AlH3-] 1
|
| 500 |
+
[2OH] 1
|
| 501 |
+
[166Ho] 1
|
| 502 |
+
[BaH2] 1
|
| 503 |
+
[P-3] 1
|
| 504 |
+
[35SH] 1
|
| 505 |
+
[Cm] 1
|
| 506 |
+
[11CH4] 1
|
| 507 |
+
[YH2] 1
|
| 508 |
+
[P+2] 1
|
| 509 |
+
[3CH] 1
|
| 510 |
+
[FH+2] 1
|
| 511 |
+
[P+5] 4
|
| 512 |
+
[Ga+3] 1
|
| 513 |
+
[Bi+5] 1
|
| 514 |
+
[Au+3] 1
|
| 515 |
+
[14C@H] 1
|
| 516 |
+
[Sm+3] 2
|
| 517 |
+
[TiH2] 1
|
| 518 |
+
[Hs] 1
|
checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/mar_members.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"members": [
|
| 3 |
+
{
|
| 4 |
+
"compress_size": 14464,
|
| 5 |
+
"modified": "2024-10-19T01:31:36",
|
| 6 |
+
"path": "models.zip",
|
| 7 |
+
"size": 15292
|
| 8 |
+
},
|
| 9 |
+
{
|
| 10 |
+
"compress_size": 3031,
|
| 11 |
+
"modified": "2024-05-21T19:03:46",
|
| 12 |
+
"path": "predict.py",
|
| 13 |
+
"size": 10598
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"compress_size": 2907,
|
| 17 |
+
"modified": "2024-10-19T01:31:36",
|
| 18 |
+
"path": "handler.py",
|
| 19 |
+
"size": 11445
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"compress_size": 2239,
|
| 23 |
+
"modified": "2024-03-29T14:02:38",
|
| 24 |
+
"path": "vocab.txt",
|
| 25 |
+
"size": 4650
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"compress_size": 2985,
|
| 29 |
+
"modified": "2024-04-11T15:23:02",
|
| 30 |
+
"path": "train.py",
|
| 31 |
+
"size": 10272
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"compress_size": 200853489,
|
| 35 |
+
"modified": "2024-10-19T01:31:36",
|
| 36 |
+
"path": "model.pt",
|
| 37 |
+
"size": 221922825
|
| 38 |
+
},
|
| 39 |
+
{
|
| 40 |
+
"compress_size": 16788,
|
| 41 |
+
"modified": "2024-10-19T01:31:36",
|
| 42 |
+
"path": "utils.zip",
|
| 43 |
+
"size": 17742
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
"compress_size": 143,
|
| 47 |
+
"modified": "2024-10-19T01:31:48",
|
| 48 |
+
"path": "MAR-INF/MANIFEST.json",
|
| 49 |
+
"size": 205
|
| 50 |
+
}
|
| 51 |
+
]
|
| 52 |
+
}
|
checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/model_args.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"accumulation_count": 16,
|
| 3 |
+
"attn_dropout": 0.1,
|
| 4 |
+
"attn_enc_filter_size": 2048,
|
| 5 |
+
"attn_enc_heads": 8,
|
| 6 |
+
"attn_enc_hidden_size": 256,
|
| 7 |
+
"attn_enc_num_layers": 6,
|
| 8 |
+
"backend": "nccl",
|
| 9 |
+
"batch_type": "tokens_sum",
|
| 10 |
+
"beam_size": 5,
|
| 11 |
+
"beta1": 0.9,
|
| 12 |
+
"beta2": 0.998,
|
| 13 |
+
"checkpoint_step_end": null,
|
| 14 |
+
"checkpoint_step_start": null,
|
| 15 |
+
"clip_norm": 20.0,
|
| 16 |
+
"compute_graph_distance": true,
|
| 17 |
+
"data_name": "pistachio_clean_Q3",
|
| 18 |
+
"decoder_attn_heads": 8,
|
| 19 |
+
"decoder_filter_size": 2048,
|
| 20 |
+
"decoder_hidden_size": 256,
|
| 21 |
+
"decoder_num_layers": 6,
|
| 22 |
+
"device": "cuda",
|
| 23 |
+
"dgat_attn_heads": 8,
|
| 24 |
+
"do_predict": false,
|
| 25 |
+
"do_profile": false,
|
| 26 |
+
"do_score": false,
|
| 27 |
+
"do_validate": false,
|
| 28 |
+
"dropout": 0.1,
|
| 29 |
+
"embed_size": 256,
|
| 30 |
+
"enable_amp": false,
|
| 31 |
+
"encoder_attn_heads": 8,
|
| 32 |
+
"encoder_emb_scale": "sqrt",
|
| 33 |
+
"encoder_filter_size": 2048,
|
| 34 |
+
"encoder_hidden_size": 256,
|
| 35 |
+
"encoder_norm": "none",
|
| 36 |
+
"encoder_num_layers": 4,
|
| 37 |
+
"encoder_positional_encoding": "none",
|
| 38 |
+
"encoder_skip_connection": "none",
|
| 39 |
+
"epoch": 2000,
|
| 40 |
+
"eps": 1e-09,
|
| 41 |
+
"eval_iter": 5000,
|
| 42 |
+
"load_from": "/home/gridsan/ztu/retrain/retro/graph2smiles/checkpoints/pistachio_clean_Q3_single_gpu_large_batch2/model.250000_24.pt",
|
| 43 |
+
"local_rank": 0,
|
| 44 |
+
"log_file": "graph2smiles_train_pistachio_clean_Q3",
|
| 45 |
+
"log_iter": 100,
|
| 46 |
+
"lr": 4.0,
|
| 47 |
+
"mask_rel_chirality": 0,
|
| 48 |
+
"max_relative_positions": 4,
|
| 49 |
+
"max_src_len": 512,
|
| 50 |
+
"max_steps": 4000000,
|
| 51 |
+
"max_tgt_len": 512,
|
| 52 |
+
"model": "graph2smiles",
|
| 53 |
+
"model_path": "/home/gridsan/ztu/retrain/retro/graph2smiles/checkpoints/pistachio_clean_Q3_single_gpu_large_batch2",
|
| 54 |
+
"mpn_type": "dgcn",
|
| 55 |
+
"n_best": 10,
|
| 56 |
+
"n_latent": "1",
|
| 57 |
+
"num_cores": 32,
|
| 58 |
+
"predict_batch_size": 4096,
|
| 59 |
+
"predict_max_len": 512,
|
| 60 |
+
"predict_min_len": 1,
|
| 61 |
+
"processed_data_path": "/home/gridsan/ztu/retrain/retro/graph2smiles/data/pistachio_clean_Q3/processed",
|
| 62 |
+
"record_shapes": false,
|
| 63 |
+
"rel_pos": "emb_only",
|
| 64 |
+
"rel_pos_buckets": 15,
|
| 65 |
+
"result_file": "",
|
| 66 |
+
"resume": true,
|
| 67 |
+
"save_iter": 10000,
|
| 68 |
+
"seed": 42,
|
| 69 |
+
"share_embeddings": false,
|
| 70 |
+
"shared_attention_layer": 0,
|
| 71 |
+
"task": "reaction_prediction",
|
| 72 |
+
"temperature": 1.0,
|
| 73 |
+
"test_output_path": "",
|
| 74 |
+
"train_batch_size": 4096,
|
| 75 |
+
"val_batch_size": 4096,
|
| 76 |
+
"verbose": false,
|
| 77 |
+
"warmup_steps": 8000,
|
| 78 |
+
"weight_decay": 0.0
|
| 79 |
+
}
|
checkpoints/askcos_retro_graph2smiles/pistachio_23q3/aux/safetensors_conversion.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"format": "safetensors",
|
| 3 |
+
"num_tensors": 297,
|
| 4 |
+
"path": "model.safetensors",
|
| 5 |
+
"roundtrip_tensor_equal": true,
|
| 6 |
+
"runtime_assets": {
|
| 7 |
+
"checkpoint_metadata": "aux/checkpoint_metadata.json",
|
| 8 |
+
"model_args": "aux/model_args.json",
|
| 9 |
+
"runtime_source_dir": "aux/graph2smiles_runtime",
|
| 10 |
+
"vocab": "aux/vocab.txt"
|
| 11 |
+
},
|
| 12 |
+
"source_member": "model.pt",
|
| 13 |
+
"status": "converted"
|
| 14 |
+
}
|
checkpoints/askcos_retro_graph2smi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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
_PAD
|
| 2 |
+
_UNK
|
| 3 |
+
_SOS
|
| 4 |
+
_EOS
|
| 5 |
+
C 71366957
|
| 6 |
+
O 26043977
|
| 7 |
+
( 42614880
|
| 8 |
+
= 14509133
|
| 9 |
+
) 42614880
|
| 10 |
+
c 88555236
|
| 11 |
+
1 23870848
|
| 12 |
+
N 11386141
|
| 13 |
+
2 15944130
|
| 14 |
+
3 7286876
|
| 15 |
+
4 2643446
|
| 16 |
+
n 9640471
|
| 17 |
+
5 812956
|
| 18 |
+
6 234756
|
| 19 |
+
[nH] 841266
|
| 20 |
+
7 74414
|
| 21 |
+
- 2618845
|
| 22 |
+
8 26942
|
| 23 |
+
[C@H] 2113649
|
| 24 |
+
o 525176
|
| 25 |
+
[C@@H] 2151298
|
| 26 |
+
S 1586078
|
| 27 |
+
[N+] 539390
|
| 28 |
+
[O-] 502732
|
| 29 |
+
s 718167
|
| 30 |
+
[C@@] 226220
|
| 31 |
+
F 5392896
|
| 32 |
+
Cl 2694145
|
| 33 |
+
# 870630
|
| 34 |
+
[Si] 364752
|
| 35 |
+
I 249124
|
| 36 |
+
P 154421
|
| 37 |
+
/ 583748
|
| 38 |
+
Br 1230889
|
| 39 |
+
B 290641
|
| 40 |
+
[C@] 256261
|
| 41 |
+
\ 138044
|
| 42 |
+
[2H] 140180
|
| 43 |
+
[N-] 81532
|
| 44 |
+
[Li] 26276
|
| 45 |
+
[Se] 3298
|
| 46 |
+
[S] 2125
|
| 47 |
+
[n+] 25340
|
| 48 |
+
[Na] 91398
|
| 49 |
+
[s+] 267
|
| 50 |
+
[C] 1245
|
| 51 |
+
[S@] 11769
|
| 52 |
+
[S@@] 10494
|
| 53 |
+
[P+] 8009
|
| 54 |
+
[Te] 188
|
| 55 |
+
[S+] 2647
|
| 56 |
+
9 9238
|
| 57 |
+
[CH2] 761
|
| 58 |
+
[K] 59765
|
| 59 |
+
[Zr-2] 22
|
| 60 |
+
[C-] 8025
|
| 61 |
+
[Hf] 106
|
| 62 |
+
[19F] 28
|
| 63 |
+
[18F] 1078
|
| 64 |
+
[Zn] 10227
|
| 65 |
+
[se] 2302
|
| 66 |
+
[Al] 1828
|
| 67 |
+
%10 3146
|
| 68 |
+
[SiH2] 2831
|
| 69 |
+
[Ca] 1528
|
| 70 |
+
[131I] 14
|
| 71 |
+
[PH] 4148
|
| 72 |
+
[Ag] 545
|
| 73 |
+
[Sn] 21897
|
| 74 |
+
[NH] 1491
|
| 75 |
+
[SH] 2131
|
| 76 |
+
[15nH] 17
|
| 77 |
+
[13c] 268
|
| 78 |
+
[Ir] 199
|
| 79 |
+
%11 1922
|
| 80 |
+
%12 1192
|
| 81 |
+
%13 802
|
| 82 |
+
%14 576
|
| 83 |
+
%15 458
|
| 84 |
+
%16 398
|
| 85 |
+
%17 272
|
| 86 |
+
%18 212
|
| 87 |
+
%19 184
|
| 88 |
+
%20 194
|
| 89 |
+
%21 132
|
| 90 |
+
[SiH] 4689
|
| 91 |
+
[Ge] 681
|
| 92 |
+
[NH2+] 3122
|
| 93 |
+
[Fe] 1209
|
| 94 |
+
[K+] 12
|
| 95 |
+
[Mg] 25244
|
| 96 |
+
[Ti] 732
|
| 97 |
+
[Cs] 10834
|
| 98 |
+
[O] 1822
|
| 99 |
+
[B-] 9477
|
| 100 |
+
[c-] 448
|
| 101 |
+
[S@@+] 291
|
| 102 |
+
[P] 1351
|
| 103 |
+
[Pd] 268
|
| 104 |
+
[SiH3] 746
|
| 105 |
+
[n-] 399
|
| 106 |
+
[11CH3] 102
|
| 107 |
+
[125I] 84
|
| 108 |
+
[CH] 554
|
| 109 |
+
[C+] 309
|
| 110 |
+
[NH3+] 4724
|
| 111 |
+
[P@] 1448
|
| 112 |
+
[P-] 52
|
| 113 |
+
[Zr] 210
|
| 114 |
+
[N] 434
|
| 115 |
+
[H] 1058
|
| 116 |
+
[N@] 534
|
| 117 |
+
[NH+] 1930
|
| 118 |
+
%22 116
|
| 119 |
+
%23 88
|
| 120 |
+
%24 82
|
| 121 |
+
[Ru] 356
|
| 122 |
+
[nH+] 2000
|
| 123 |
+
[PH2] 345
|
| 124 |
+
[P@@] 1221
|
| 125 |
+
[YH] 20
|
| 126 |
+
[N@@] 517
|
| 127 |
+
[c+] 45
|
| 128 |
+
[Mn] 1047
|
| 129 |
+
[o+] 238
|
| 130 |
+
[cH-] 259
|
| 131 |
+
[SeH] 168
|
| 132 |
+
[Pt] 183
|
| 133 |
+
[p+] 6
|
| 134 |
+
[99Tc] 2
|
| 135 |
+
[BH] 216
|
| 136 |
+
[S@+] 272
|
| 137 |
+
p 336
|
| 138 |
+
[Cu] 3973
|
| 139 |
+
[211At] 8
|
| 140 |
+
[IrH2] 3
|
| 141 |
+
[pH] 12
|
| 142 |
+
[Pb] 371
|
| 143 |
+
[Si@@H] 275
|
| 144 |
+
[CH+] 63
|
| 145 |
+
[te] 203
|
| 146 |
+
[Tb] 4
|
| 147 |
+
[Co] 173
|
| 148 |
+
[Cl+] 1706
|
| 149 |
+
[S-] 1123
|
| 150 |
+
[In] 74
|
| 151 |
+
[Nb] 40
|
| 152 |
+
[Be] 24
|
| 153 |
+
[B] 377
|
| 154 |
+
[O+] 4734
|
| 155 |
+
[OH2+] 18
|
| 156 |
+
[13C] 303
|
| 157 |
+
%25 64
|
| 158 |
+
[123I] 51
|
| 159 |
+
%26 46
|
| 160 |
+
%27 50
|
| 161 |
+
%28 60
|
| 162 |
+
%29 44
|
| 163 |
+
%30 40
|
| 164 |
+
%31 42
|
| 165 |
+
%32 50
|
| 166 |
+
%33 34
|
| 167 |
+
%34 34
|
| 168 |
+
%35 24
|
| 169 |
+
%36 36
|
| 170 |
+
%37 26
|
| 171 |
+
%38 24
|
| 172 |
+
%39 24
|
| 173 |
+
%40 32
|
| 174 |
+
%41 24
|
| 175 |
+
%42 24
|
| 176 |
+
%43 20
|
| 177 |
+
[W] 36
|
| 178 |
+
[N@+] 44
|
| 179 |
+
[13CH2] 127
|
| 180 |
+
[Sc] 7
|
| 181 |
+
[As] 203
|
| 182 |
+
[SiH4] 40
|
| 183 |
+
[14c] 17
|
| 184 |
+
[AlH] 875
|
| 185 |
+
[Na+] 97
|
| 186 |
+
[CH-] 208
|
| 187 |
+
[OH+] 108
|
| 188 |
+
[SH2] 78
|
| 189 |
+
[Zn+2] 36
|
| 190 |
+
[68Ga] 2
|
| 191 |
+
[Hg] 131
|
| 192 |
+
[Cr] 1600
|
| 193 |
+
[Ni] 173
|
| 194 |
+
[Sb] 127
|
| 195 |
+
[13cH] 109
|
| 196 |
+
[CH2-] 295
|
| 197 |
+
[Ta] 25
|
| 198 |
+
[I+] 272
|
| 199 |
+
[Lu] 23
|
| 200 |
+
[Sr] 11
|
| 201 |
+
[Si@] 154
|
| 202 |
+
[Si@@] 151
|
| 203 |
+
[Mo] 206
|
| 204 |
+
[siH] 14
|
| 205 |
+
[15NH2] 49
|
| 206 |
+
[11c] 1
|
| 207 |
+
[TeH] 40
|
| 208 |
+
[I-] 15
|
| 209 |
+
[Ga] 37
|
| 210 |
+
[Gd] 8
|
| 211 |
+
[Tc] 3
|
| 212 |
+
[Pr] 2
|
| 213 |
+
[GeH3] 7
|
| 214 |
+
[124I] 15
|
| 215 |
+
[13CH3] 151
|
| 216 |
+
[15N] 18
|
| 217 |
+
[NH-] 495
|
| 218 |
+
[CH2+] 172
|
| 219 |
+
[H+] 145
|
| 220 |
+
[I+2] 20
|
| 221 |
+
[P@@H] 2
|
| 222 |
+
[64Cu] 1
|
| 223 |
+
[14C] 59
|
| 224 |
+
[Li+] 9
|
| 225 |
+
[La] 108
|
| 226 |
+
[TeH3] 4
|
| 227 |
+
[SbH2] 4
|
| 228 |
+
[Bi] 270
|
| 229 |
+
[BH3-] 1781
|
| 230 |
+
[13CH] 22
|
| 231 |
+
[B@@-] 4
|
| 232 |
+
[15N+] 7
|
| 233 |
+
[15NH] 22
|
| 234 |
+
[15OH] 1
|
| 235 |
+
[Ne] 5
|
| 236 |
+
[Ba] 21
|
| 237 |
+
[Au] 121
|
| 238 |
+
[Fm] 10
|
| 239 |
+
[Eu] 17
|
| 240 |
+
[Si@H] 67
|
| 241 |
+
[14CH] 23
|
| 242 |
+
[GeH2] 3
|
| 243 |
+
[c] 15
|
| 244 |
+
[N@@+] 25
|
| 245 |
+
[S+2] 74
|
| 246 |
+
[Th] 4
|
| 247 |
+
[SnH2] 30
|
| 248 |
+
[SnH] 333
|
| 249 |
+
[11C] 9
|
| 250 |
+
[InH2] 18
|
| 251 |
+
[U] 2
|
| 252 |
+
[As+] 5
|
| 253 |
+
b 22
|
| 254 |
+
[Ag+] 41
|
| 255 |
+
[14cH] 4
|
| 256 |
+
[SH+] 58
|
| 257 |
+
[Rh] 31
|
| 258 |
+
[IH] 38
|
| 259 |
+
[Os] 12
|
| 260 |
+
[Gd+3] 34
|
| 261 |
+
[3H] 178
|
| 262 |
+
[cH+] 61
|
| 263 |
+
[Ce] 60
|
| 264 |
+
[B@-] 8
|
| 265 |
+
[SnH3] 80
|
| 266 |
+
[Re] 12
|
| 267 |
+
[PH+] 248
|
| 268 |
+
[15NH2+] 2
|
| 269 |
+
[AsH2] 4
|
| 270 |
+
[18O] 23
|
| 271 |
+
[Sn+2] 10
|
| 272 |
+
[I+3] 867
|
| 273 |
+
[13C-] 2
|
| 274 |
+
[Mg+] 5
|
| 275 |
+
[Cl+2] 20
|
| 276 |
+
[10B] 7
|
| 277 |
+
[TaH3] 3
|
| 278 |
+
[NiH] 3
|
| 279 |
+
[15n] 18
|
| 280 |
+
[113C] 2
|
| 281 |
+
[CH3+] 37
|
| 282 |
+
[se+] 16
|
| 283 |
+
[IrH] 9
|
| 284 |
+
[Au-] 3
|
| 285 |
+
[TiH] 5
|
| 286 |
+
[14CH3] 24
|
| 287 |
+
[V] 17
|
| 288 |
+
[Fe+2] 116
|
| 289 |
+
[Cl+3] 268
|
| 290 |
+
[AsH] 10
|
| 291 |
+
[32P] 8
|
| 292 |
+
[SH4] 5
|
| 293 |
+
[Mn+2] 2
|
| 294 |
+
[F-] 2223
|
| 295 |
+
[13C@@H] 3
|
| 296 |
+
[GeH] 12
|
| 297 |
+
[N@H+] 6
|
| 298 |
+
[ZrH2] 1
|
| 299 |
+
[Cu+] 8
|
| 300 |
+
[F+] 7
|
| 301 |
+
[14C@@H] 2
|
| 302 |
+
[3Si] 2
|
| 303 |
+
[Rh+] 1
|
| 304 |
+
[P@@+] 1
|
| 305 |
+
%44 8
|
| 306 |
+
%45 8
|
| 307 |
+
%46 8
|
| 308 |
+
%47 8
|
| 309 |
+
%48 4
|
| 310 |
+
%49 4
|
| 311 |
+
[Si-] 33
|
| 312 |
+
[17O] 4
|
| 313 |
+
[Y] 3
|
| 314 |
+
[Po] 2
|
| 315 |
+
[te+] 2
|
| 316 |
+
[si] 5
|
| 317 |
+
[16F] 3
|
| 318 |
+
[79Br] 1
|
| 319 |
+
[Se+] 2
|
| 320 |
+
[CaH] 2
|
| 321 |
+
[177Lu] 2
|
| 322 |
+
[Cu-2] 4
|
| 323 |
+
[13NH2] 1
|
| 324 |
+
[Ho] 4
|
| 325 |
+
[PH4] 8
|
| 326 |
+
[Br+2] 34
|
| 327 |
+
[Cu+2] 77
|
| 328 |
+
[14CH2] 8
|
| 329 |
+
[4He] 1
|
| 330 |
+
[SbH] 2
|
| 331 |
+
[NaH] 1
|
| 332 |
+
[Ar] 19
|
| 333 |
+
[N+2] 3
|
| 334 |
+
[5O] 1
|
| 335 |
+
[N@@H+] 6
|
| 336 |
+
[ClH+] 4
|
| 337 |
+
[Ti+] 1
|
| 338 |
+
[AlH3] 3
|
| 339 |
+
[BH-] 2762
|
| 340 |
+
[Yb] 7
|
| 341 |
+
[Ba+2] 64
|
| 342 |
+
[Cr+] 1
|
| 343 |
+
[He] 3
|
| 344 |
+
[RuH] 8
|
| 345 |
+
[Li-2] 2
|
| 346 |
+
[Dy] 2
|
| 347 |
+
[Si+] 8
|
| 348 |
+
[YH3] 1
|
| 349 |
+
[Co+2] 125
|
| 350 |
+
[Ni+2] 7
|
| 351 |
+
[Sb-] 8
|
| 352 |
+
[Fe+3] 23
|
| 353 |
+
[Zn+] 12
|
| 354 |
+
. 2797764
|
| 355 |
+
[Bi+2] 4
|
| 356 |
+
[Ir+] 2
|
| 357 |
+
[H-] 296
|
| 358 |
+
[AlH2-] 59
|
| 359 |
+
[S-2] 120
|
| 360 |
+
[Eu+3] 2
|
| 361 |
+
[Fe-4] 64
|
| 362 |
+
[AlH-] 19
|
| 363 |
+
[PH4+] 9
|
| 364 |
+
[Fe-3] 30
|
| 365 |
+
[In+3] 2
|
| 366 |
+
* 166
|
| 367 |
+
[Pt-2] 9
|
| 368 |
+
[Al-] 30
|
| 369 |
+
[Cs+] 16
|
| 370 |
+
[Tl+3] 20
|
| 371 |
+
[Sb+5] 7
|
| 372 |
+
[Se-] 6
|
| 373 |
+
[Pb+2] 9
|
| 374 |
+
[Hf+2] 19
|
| 375 |
+
[Yb+3] 37
|
| 376 |
+
[Ce+4] 115
|
| 377 |
+
[PH2+] 10
|
| 378 |
+
[BH4-] 214
|
| 379 |
+
[PH3] 26
|
| 380 |
+
[PH3+] 103
|
| 381 |
+
[AlH4-] 44
|
| 382 |
+
[Al+3] 39
|
| 383 |
+
[Al+] 77
|
| 384 |
+
[CH3-] 98
|
| 385 |
+
[Ti+3] 67
|
| 386 |
+
[AlH4] 8
|
| 387 |
+
[Ti+4] 4
|
| 388 |
+
[Ce+3] 47
|
| 389 |
+
[Tl] 24
|
| 390 |
+
[P+3] 54
|
| 391 |
+
[sH+] 12
|
| 392 |
+
[Tl+] 22
|
| 393 |
+
[SH3+] 2
|
| 394 |
+
[SeH2] 15
|
| 395 |
+
[Sr+2] 4
|
| 396 |
+
[Ti+2] 10
|
| 397 |
+
[SeH-] 8
|
| 398 |
+
[Br+] 26
|
| 399 |
+
[SH2+] 14
|
| 400 |
+
[TeH2] 1
|
| 401 |
+
[F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2
|
| 456 |
+
[WH] 1
|
| 457 |
+
[Fr] 1
|
| 458 |
+
[W+6] 1
|
| 459 |
+
[Y+3] 2
|
| 460 |
+
[No] 1
|
| 461 |
+
[Sn-] 1
|
| 462 |
+
[1H] 2
|
| 463 |
+
[YH7] 1
|
| 464 |
+
[IH2] 1
|
| 465 |
+
[Se-2] 1
|
| 466 |
+
[Ta+5] 1
|
| 467 |
+
[Cd+2] 1
|
| 468 |
+
[B+2] 7
|
| 469 |
+
[Sb+2] 1
|
| 470 |
+
[SiH4+] 1
|
| 471 |
+
[C+2] 4
|
| 472 |
+
[P@H] 1
|
| 473 |
+
[NH+3] 1
|
| 474 |
+
[Se+2] 1
|
| 475 |
+
[oH+] 1
|
| 476 |
+
[p-] 1
|
| 477 |
+
[18OH] 1
|
| 478 |
+
[Co+3] 1
|
| 479 |
+
[Y-] 1
|
| 480 |
+
[C-4] 1
|
| 481 |
+
[2H+] 1
|
| 482 |
+
[3H+] 1
|
| 483 |
+
[BiH3] 1
|
| 484 |
+
[FH+] 1
|
| 485 |
+
[PH-] 4
|
| 486 |
+
[Ge+4] 1
|
| 487 |
+
[AsH3] 1
|
| 488 |
+
[Sm+2] 1
|
| 489 |
+
[As+3] 2
|
| 490 |
+
[Br+3] 1
|
| 491 |
+
[SH3] 1
|
| 492 |
+
[BrH+] 2
|
| 493 |
+
[113CH3] 1
|
| 494 |
+
[Ta+2] 1
|
| 495 |
+
[NH3+2] 2
|
| 496 |
+
[Yb+2] 1
|
| 497 |
+
[Cr+2] 2
|
| 498 |
+
[I] 1
|
| 499 |
+
[AlH3-] 1
|
| 500 |
+
[2OH] 1
|
| 501 |
+
[166Ho] 1
|
| 502 |
+
[BaH2] 1
|
| 503 |
+
[P-3] 1
|
| 504 |
+
[35SH] 1
|
| 505 |
+
[Cm] 1
|
| 506 |
+
[11CH4] 1
|
| 507 |
+
[YH2] 1
|
| 508 |
+
[P+2] 1
|
| 509 |
+
[3CH] 1
|
| 510 |
+
[FH+2] 1
|
| 511 |
+
[P+5] 4
|
| 512 |
+
[Ga+3] 1
|
| 513 |
+
[Bi+5] 1
|
| 514 |
+
[Au+3] 1
|
| 515 |
+
[14C@H] 1
|
| 516 |
+
[Sm+3] 2
|
| 517 |
+
[TiH2] 1
|
| 518 |
+
[Hs] 1
|
checkpoints/askcos_retro_graph2smiles/pistachio_23q3/benchmarks/default_test.jsonl
ADDED
|
File without changes
|
checkpoints/askcos_retro_graph2smiles/pistachio_23q3/benchmarks/metadata.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"benchmark_variant": "benchmark_pending",
|
| 3 |
+
"built_at": "1970-01-01T00:00:00+00:00",
|
| 4 |
+
"checkpoint_id": "pistachio_23q3",
|
| 5 |
+
"dataset_id": "askcos_retro_graph2smiles_pistachio_23q3_benchmark_pending",
|
| 6 |
+
"dataset_ref": "askcos_pistachio_23q3_release",
|
| 7 |
+
"native_input_format": "benchmark_not_available",
|
| 8 |
+
"native_sources": [],
|
| 9 |
+
"notes": [
|
| 10 |
+
"No redistribution-safe native benchmark split for this ASKCOS model archive is staged in this repository.",
|
| 11 |
+
"The bundle keeps benchmark metadata so downstream tooling can distinguish unavailable benchmarks from accidental omissions."
|
| 12 |
+
],
|
| 13 |
+
"num_examples": 0,
|
| 14 |
+
"split": "test"
|
| 15 |
+
}
|
checkpoints/askcos_retro_graph2smiles/pistachio_23q3/manifest.json
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"auxiliary_files": [
|
| 3 |
+
"aux/MAR-INF/MANIFEST.json",
|
| 4 |
+
"aux/checkpoint_metadata.json",
|
| 5 |
+
"aux/graph2smiles_runtime/models/attention_xl.py",
|
| 6 |
+
"aux/graph2smiles_runtime/models/dgat.py",
|
| 7 |
+
"aux/graph2smiles_runtime/models/dgcn.py",
|
| 8 |
+
"aux/graph2smiles_runtime/models/graph2smiles.py",
|
| 9 |
+
"aux/graph2smiles_runtime/models/graphfeat.py",
|
| 10 |
+
"aux/graph2smiles_runtime/models/model_utils.py",
|
| 11 |
+
"aux/graph2smiles_runtime/models/transformer_decoder.py",
|
| 12 |
+
"aux/graph2smiles_runtime/predict.py",
|
| 13 |
+
"aux/graph2smiles_runtime/train.py",
|
| 14 |
+
"aux/graph2smiles_runtime/utils/c_calculate.so",
|
| 15 |
+
"aux/graph2smiles_runtime/utils/chem_utils.py",
|
| 16 |
+
"aux/graph2smiles_runtime/utils/ctypes_calculator.py",
|
| 17 |
+
"aux/graph2smiles_runtime/utils/data_utils.py",
|
| 18 |
+
"aux/graph2smiles_runtime/utils/parsing.py",
|
| 19 |
+
"aux/graph2smiles_runtime/utils/preprocess_utils.py",
|
| 20 |
+
"aux/graph2smiles_runtime/utils/rxn_graphs.py",
|
| 21 |
+
"aux/graph2smiles_runtime/utils/train_utils.py",
|
| 22 |
+
"aux/mar_files/handler.py",
|
| 23 |
+
"aux/mar_files/models.zip",
|
| 24 |
+
"aux/mar_files/predict.py",
|
| 25 |
+
"aux/mar_files/train.py",
|
| 26 |
+
"aux/mar_files/utils.zip",
|
| 27 |
+
"aux/mar_files/vocab.txt",
|
| 28 |
+
"aux/mar_members.json",
|
| 29 |
+
"aux/model_args.json",
|
| 30 |
+
"aux/safetensors_conversion.json",
|
| 31 |
+
"aux/vocab.txt",
|
| 32 |
+
"benchmarks/default_test.jsonl",
|
| 33 |
+
"benchmarks/metadata.json"
|
| 34 |
+
],
|
| 35 |
+
"benchmark_datasets": [
|
| 36 |
+
{
|
| 37 |
+
"benchmark_variant": "benchmark_pending",
|
| 38 |
+
"dataset_id": "askcos_retro_graph2smiles_pistachio_23q3_benchmark_pending",
|
| 39 |
+
"dataset_ref": "askcos_pistachio_23q3_release",
|
| 40 |
+
"default": true,
|
| 41 |
+
"format": "jsonl",
|
| 42 |
+
"metadata_path": "benchmarks/metadata.json",
|
| 43 |
+
"native_input_format": "benchmark_not_available",
|
| 44 |
+
"native_source_paths": [],
|
| 45 |
+
"notes": [
|
| 46 |
+
"No redistribution-safe native benchmark split for this ASKCOS model archive is staged in this repository.",
|
| 47 |
+
"The bundle keeps benchmark metadata so downstream tooling can distinguish unavailable benchmarks from accidental omissions."
|
| 48 |
+
],
|
| 49 |
+
"num_examples": 0,
|
| 50 |
+
"path": "benchmarks/default_test.jsonl",
|
| 51 |
+
"split": "test"
|
| 52 |
+
}
|
| 53 |
+
],
|
| 54 |
+
"checkpoint_id": "pistachio_23q3",
|
| 55 |
+
"contained_artifact_bindings": [
|
| 56 |
+
{
|
| 57 |
+
"canonical_split_family": "askcos_pistachio_23q3_split_unspecified",
|
| 58 |
+
"dataset_ref": "askcos_pistachio_23q3_release",
|
| 59 |
+
"path": "modelos_ASKCOS/pistachio_23Q3_new.mar",
|
| 60 |
+
"stage": "released_torchserve_archive"
|
| 61 |
+
}
|
| 62 |
+
],
|
| 63 |
+
"conversion": {
|
| 64 |
+
"converted_at": "1970-01-01T00:00:00+00:00",
|
| 65 |
+
"notes": [
|
| 66 |
+
"The upstream ASKCOS TorchServe .mar was unpacked into native bundle assets.",
|
| 67 |
+
"Tensor weights are stored canonically as model.safetensors; non-tensor runtime assets are stored under aux/.",
|
| 68 |
+
"The original .mar archive is not required for wrapper inference."
|
| 69 |
+
],
|
| 70 |
+
"safetensors": {
|
| 71 |
+
"format": "safetensors",
|
| 72 |
+
"num_tensors": 297,
|
| 73 |
+
"path": "model.safetensors",
|
| 74 |
+
"roundtrip_tensor_equal": true,
|
| 75 |
+
"runtime_assets": {
|
| 76 |
+
"checkpoint_metadata": "aux/checkpoint_metadata.json",
|
| 77 |
+
"model_args": "aux/model_args.json",
|
| 78 |
+
"runtime_source_dir": "aux/graph2smiles_runtime",
|
| 79 |
+
"vocab": "aux/vocab.txt"
|
| 80 |
+
},
|
| 81 |
+
"source_member": "model.pt",
|
| 82 |
+
"status": "converted"
|
| 83 |
+
},
|
| 84 |
+
"source_format": "torchserve_mar_embedded_checkpoint",
|
| 85 |
+
"status": "converted",
|
| 86 |
+
"tool_version": "initial"
|
| 87 |
+
},
|
| 88 |
+
"display_name": "ASKCOS Retro Graph2SMILES pistachio_23Q3",
|
| 89 |
+
"embedding_supported": false,
|
| 90 |
+
"fine_tuning": {
|
| 91 |
+
"adapter_overlay_dir": "adapters",
|
| 92 |
+
"base_weights_path": "model.safetensors",
|
| 93 |
+
"notes": [
|
| 94 |
+
"This package preserves immutable base weights in model.safetensors and reserves adapters/ for future fine-tuning or LoRA overlays."
|
| 95 |
+
]
|
| 96 |
+
},
|
| 97 |
+
"format_version": 1,
|
| 98 |
+
"generated_at": "1970-01-01T00:00:00+00:00",
|
| 99 |
+
"input_schema": {
|
| 100 |
+
"product_field": "smiles",
|
| 101 |
+
"request_format": {
|
| 102 |
+
"smiles": [
|
| 103 |
+
"product_smiles"
|
| 104 |
+
]
|
| 105 |
+
},
|
| 106 |
+
"target_field": "reactants"
|
| 107 |
+
},
|
| 108 |
+
"model_id": "askcos_retro_graph2smiles",
|
| 109 |
+
"normalized_checkpoint_id": "pistachio_23q3",
|
| 110 |
+
"package_layout": {
|
| 111 |
+
"adapters_dir": "adapters",
|
| 112 |
+
"aux_dir": "aux",
|
| 113 |
+
"benchmarks_dir": "benchmarks",
|
| 114 |
+
"weights_path": "model.safetensors"
|
| 115 |
+
},
|
| 116 |
+
"source_registry_refs": [
|
| 117 |
+
{
|
| 118 |
+
"checkpoint_id": "pistachio_23q3",
|
| 119 |
+
"model_id": "askcos_retro_graph2smiles"
|
| 120 |
+
}
|
| 121 |
+
],
|
| 122 |
+
"split_provenance": [
|
| 123 |
+
{
|
| 124 |
+
"canonical_split_family": "askcos_pistachio_23q3_split_unspecified",
|
| 125 |
+
"dataset_ref": "askcos_pistachio_23q3_release",
|
| 126 |
+
"split_names": [],
|
| 127 |
+
"stage": "released_torchserve_archive"
|
| 128 |
+
},
|
| 129 |
+
{
|
| 130 |
+
"canonical_split_family": "askcos_pistachio_23q3_split_unspecified",
|
| 131 |
+
"dataset_ref": "askcos_pistachio_23q3_release",
|
| 132 |
+
"path": "modelos_ASKCOS/pistachio_23Q3_new.mar",
|
| 133 |
+
"stage": "released_torchserve_archive"
|
| 134 |
+
}
|
| 135 |
+
],
|
| 136 |
+
"task_direction": "retrosynthesis",
|
| 137 |
+
"training_dataset_refs": [
|
| 138 |
+
"askcos_pistachio_23q3_release"
|
| 139 |
+
],
|
| 140 |
+
"training_stage_bindings": [
|
| 141 |
+
{
|
| 142 |
+
"canonical_split_family": "askcos_pistachio_23q3_split_unspecified",
|
| 143 |
+
"dataset_ref": "askcos_pistachio_23q3_release",
|
| 144 |
+
"split_names": [],
|
| 145 |
+
"stage": "released_torchserve_archive"
|
| 146 |
+
},
|
| 147 |
+
{
|
| 148 |
+
"canonical_split_family": "askcos_pistachio_23q3_split_unspecified",
|
| 149 |
+
"dataset_ref": "askcos_pistachio_23q3_release",
|
| 150 |
+
"path": "modelos_ASKCOS/pistachio_23Q3_new.mar",
|
| 151 |
+
"stage": "released_torchserve_archive"
|
| 152 |
+
}
|
| 153 |
+
],
|
| 154 |
+
"weights": {
|
| 155 |
+
"dtype_summary": "float tensors preserved from upstream checkpoint",
|
| 156 |
+
"framework": "pytorch",
|
| 157 |
+
"path": "model.safetensors",
|
| 158 |
+
"tensor_namespace": "askcos_graph2smiles"
|
| 159 |
+
},
|
| 160 |
+
"wrapper_config": "wrapper_config.json",
|
| 161 |
+
"wrapper_family": "askcos_graph2smiles"
|
| 162 |
+
}
|
checkpoints/askcos_retro_graph2smiles/pistachio_23q3/provenance.json
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"conversion_notes": [
|
| 3 |
+
"The ASKCOS TorchServe .mar source archive was unpacked; model.mar is not copied into the normalized package.",
|
| 4 |
+
"Embedded tensor weights were serialized to model.safetensors and verified by safetensors round-trip equality.",
|
| 5 |
+
"Required non-tensor runtime assets such as templates, vocabularies, model args, OpenNMT metadata, and Graph2SMILES source support files are copied under aux/.",
|
| 6 |
+
"Lightweight MAR metadata is retained under aux/ for provenance only."
|
| 7 |
+
],
|
| 8 |
+
"copied_sidecars": [
|
| 9 |
+
"aux/MAR-INF/MANIFEST.json",
|
| 10 |
+
"aux/checkpoint_metadata.json",
|
| 11 |
+
"aux/graph2smiles_runtime/models/attention_xl.py",
|
| 12 |
+
"aux/graph2smiles_runtime/models/dgat.py",
|
| 13 |
+
"aux/graph2smiles_runtime/models/dgcn.py",
|
| 14 |
+
"aux/graph2smiles_runtime/models/graph2smiles.py",
|
| 15 |
+
"aux/graph2smiles_runtime/models/graphfeat.py",
|
| 16 |
+
"aux/graph2smiles_runtime/models/model_utils.py",
|
| 17 |
+
"aux/graph2smiles_runtime/models/transformer_decoder.py",
|
| 18 |
+
"aux/graph2smiles_runtime/predict.py",
|
| 19 |
+
"aux/graph2smiles_runtime/train.py",
|
| 20 |
+
"aux/graph2smiles_runtime/utils/c_calculate.so",
|
| 21 |
+
"aux/graph2smiles_runtime/utils/chem_utils.py",
|
| 22 |
+
"aux/graph2smiles_runtime/utils/ctypes_calculator.py",
|
| 23 |
+
"aux/graph2smiles_runtime/utils/data_utils.py",
|
| 24 |
+
"aux/graph2smiles_runtime/utils/parsing.py",
|
| 25 |
+
"aux/graph2smiles_runtime/utils/preprocess_utils.py",
|
| 26 |
+
"aux/graph2smiles_runtime/utils/rxn_graphs.py",
|
| 27 |
+
"aux/graph2smiles_runtime/utils/train_utils.py",
|
| 28 |
+
"aux/mar_files/handler.py",
|
| 29 |
+
"aux/mar_files/models.zip",
|
| 30 |
+
"aux/mar_files/predict.py",
|
| 31 |
+
"aux/mar_files/train.py",
|
| 32 |
+
"aux/mar_files/utils.zip",
|
| 33 |
+
"aux/mar_files/vocab.txt",
|
| 34 |
+
"aux/mar_members.json",
|
| 35 |
+
"aux/model_args.json",
|
| 36 |
+
"aux/safetensors_conversion.json",
|
| 37 |
+
"aux/vocab.txt"
|
| 38 |
+
],
|
| 39 |
+
"inner_members": [
|
| 40 |
+
{
|
| 41 |
+
"archive_path": "datasets/modelos_ASKCOS/pistachio_23Q3_new.mar",
|
| 42 |
+
"member": "models.zip",
|
| 43 |
+
"role": "archive_member"
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
"archive_path": "datasets/modelos_ASKCOS/pistachio_23Q3_new.mar",
|
| 47 |
+
"member": "predict.py",
|
| 48 |
+
"role": "archive_member"
|
| 49 |
+
},
|
| 50 |
+
{
|
| 51 |
+
"archive_path": "datasets/modelos_ASKCOS/pistachio_23Q3_new.mar",
|
| 52 |
+
"member": "handler.py",
|
| 53 |
+
"role": "archive_member"
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"archive_path": "datasets/modelos_ASKCOS/pistachio_23Q3_new.mar",
|
| 57 |
+
"member": "vocab.txt",
|
| 58 |
+
"role": "archive_member"
|
| 59 |
+
},
|
| 60 |
+
{
|
| 61 |
+
"archive_path": "datasets/modelos_ASKCOS/pistachio_23Q3_new.mar",
|
| 62 |
+
"member": "train.py",
|
| 63 |
+
"role": "archive_member"
|
| 64 |
+
},
|
| 65 |
+
{
|
| 66 |
+
"archive_path": "datasets/modelos_ASKCOS/pistachio_23Q3_new.mar",
|
| 67 |
+
"member": "model.pt",
|
| 68 |
+
"role": "weights_source"
|
| 69 |
+
},
|
| 70 |
+
{
|
| 71 |
+
"archive_path": "datasets/modelos_ASKCOS/pistachio_23Q3_new.mar",
|
| 72 |
+
"member": "utils.zip",
|
| 73 |
+
"role": "archive_member"
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"archive_path": "datasets/modelos_ASKCOS/pistachio_23Q3_new.mar",
|
| 77 |
+
"member": "MAR-INF/MANIFEST.json",
|
| 78 |
+
"role": "torchserve_manifest"
|
| 79 |
+
}
|
| 80 |
+
],
|
| 81 |
+
"normalized_checkpoint_id": "pistachio_23q3",
|
| 82 |
+
"source_artifacts": [
|
| 83 |
+
{
|
| 84 |
+
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/modelos_ASKCOS/pistachio_23Q3_new.mar",
|
| 85 |
+
"kind": "local_repo_file",
|
| 86 |
+
"path": "datasets/modelos_ASKCOS/pistachio_23Q3_new.mar",
|
| 87 |
+
"role": "source_artifact",
|
| 88 |
+
"sha256": "0014b36719ede8ec80cbbcf22148a7d48d65a9a0710e4474b2338ac08f744ff9",
|
| 89 |
+
"size": 200896846
|
| 90 |
+
},
|
| 91 |
+
{
|
| 92 |
+
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/modelos_ASKCOS/download_trained_models.sh",
|
| 93 |
+
"kind": "local_repo_file",
|
| 94 |
+
"path": "datasets/modelos_ASKCOS/download_trained_models.sh",
|
| 95 |
+
"role": "source_artifact",
|
| 96 |
+
"sha256": "e88d26f86ce79d2c7d8f05d1a59e3b1b88bde69c3afb95d065c932ff058092be",
|
| 97 |
+
"size": 2374
|
| 98 |
+
},
|
| 99 |
+
{
|
| 100 |
+
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/modelos_ASKCOS/download_trained_models2.sh",
|
| 101 |
+
"kind": "local_repo_file",
|
| 102 |
+
"path": "datasets/modelos_ASKCOS/download_trained_models2.sh",
|
| 103 |
+
"role": "source_artifact",
|
| 104 |
+
"sha256": "c2351dd12f68b0f372b23183cf470fa643f73274f66e34dfc0dacd1ce1a9843e",
|
| 105 |
+
"size": 1234
|
| 106 |
+
}
|
| 107 |
+
]
|
| 108 |
+
}
|
checkpoints/askcos_retro_graph2smiles/pistachio_23q3/wrapper_config.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architecture_class": "Graph2SMILES",
|
| 3 |
+
"device_supported": [
|
| 4 |
+
"cpu",
|
| 5 |
+
"cuda"
|
| 6 |
+
],
|
| 7 |
+
"fine_tuning": {
|
| 8 |
+
"adapter_overlay_dir": "adapters",
|
| 9 |
+
"base_weights_path": "model.safetensors",
|
| 10 |
+
"notes": [
|
| 11 |
+
"Base weights stay immutable in model.safetensors; future fine-tuning or LoRA adapters should be added as overlays under adapters/."
|
| 12 |
+
]
|
| 13 |
+
},
|
| 14 |
+
"input_schema": {
|
| 15 |
+
"product_field": "smiles",
|
| 16 |
+
"request_format": {
|
| 17 |
+
"smiles": [
|
| 18 |
+
"product_smiles"
|
| 19 |
+
]
|
| 20 |
+
},
|
| 21 |
+
"target_field": "reactants"
|
| 22 |
+
},
|
| 23 |
+
"license": "mit",
|
| 24 |
+
"loader": {
|
| 25 |
+
"checkpoint_metadata": "aux/checkpoint_metadata.json",
|
| 26 |
+
"kind": "askcos_graph2smiles_safetensors",
|
| 27 |
+
"model_args": "aux/model_args.json",
|
| 28 |
+
"model_version": "1.0",
|
| 29 |
+
"runtime_source_dir": "aux/graph2smiles_runtime",
|
| 30 |
+
"served_model_name": "pistachio_clean_Q3",
|
| 31 |
+
"source_handler": "handler.py",
|
| 32 |
+
"state_dict_format": "safetensors",
|
| 33 |
+
"vocab": "aux/vocab.txt"
|
| 34 |
+
},
|
| 35 |
+
"package_layout": {
|
| 36 |
+
"adapters_dir": "adapters",
|
| 37 |
+
"aux_dir": "aux",
|
| 38 |
+
"weights_path": "model.safetensors"
|
| 39 |
+
},
|
| 40 |
+
"runtime_file_map": {
|
| 41 |
+
"aux/checkpoint_metadata.json": "aux/checkpoint_metadata.json",
|
| 42 |
+
"aux/graph2smiles_runtime": "aux/graph2smiles_runtime",
|
| 43 |
+
"aux/model_args.json": "aux/model_args.json",
|
| 44 |
+
"aux/vocab.txt": "aux/vocab.txt",
|
| 45 |
+
"model.safetensors": "model.safetensors"
|
| 46 |
+
},
|
| 47 |
+
"task_direction": "retrosynthesis",
|
| 48 |
+
"wrapper_family": "askcos_graph2smiles"
|
| 49 |
+
}
|
checkpoints/askcos_retro_graph2smiles/uspto_full/SHA256SUMS
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
5a52b4f5610a621fb55c1f57ae798d713fbec01db7524b37680c9861c0954361 aux/MAR-INF/MANIFEST.json
|
| 2 |
+
0c89b43faae2b20a087382c2180bc0b276b997725ed1ad474277faf32bd5edcd aux/checkpoint_metadata.json
|
| 3 |
+
b7f0a220dcbb261ea2dc3ac8e16c86a4b508cf012da5d5e250ab82c0dcbb9794 aux/graph2smiles_runtime/models/attention_xl.py
|
| 4 |
+
59e5e707bf6298eaa63fccfcb638719f280579b08ccc969bb3075c2a07a9cc22 aux/graph2smiles_runtime/models/dgat.py
|
| 5 |
+
0f9c77867fa1a53c18d893dab68a57f94bbaa326f8ff63e374860c45a11b1e6c aux/graph2smiles_runtime/models/dgcn.py
|
| 6 |
+
26260eb71e0da0f998d63c391641a6aa782171ed0c670c4f07014402a5073ff5 aux/graph2smiles_runtime/models/graph2smiles.py
|
| 7 |
+
fbbbec61d02ddb6b9d90720b2d5b0a04a399a0abe9b1575ed4f8d428a7638f75 aux/graph2smiles_runtime/models/graphfeat.py
|
| 8 |
+
3b85acd86c407470536395cf85b8af99dc067f67f31897c42dc00f4a32f772c3 aux/graph2smiles_runtime/models/model_utils.py
|
| 9 |
+
d5c87645c9f7ebc96d23d3ae94c8692ffcd798e60e2b52d6d876505752eb007b aux/graph2smiles_runtime/models/transformer_decoder.py
|
| 10 |
+
9309e0352e4fb7f6c00b8dccd1bd4300ed91f7660533e3ace9db8e61645caa26 aux/graph2smiles_runtime/predict.py
|
| 11 |
+
fb3b0374bcf3773e87926bce4160aa30bd9088e71b56b3daa617de2cb03892fa aux/graph2smiles_runtime/train.py
|
| 12 |
+
f7e98befeb3a532d72595f3f64728dbf32d2daa8ba91ad8e451eed16e31d244b aux/graph2smiles_runtime/utils/c_calculate.so
|
| 13 |
+
2f440d3b147d5eb16158a0eff7872bf54939a77f73d5569d229fac82f3e640d3 aux/graph2smiles_runtime/utils/chem_utils.py
|
| 14 |
+
458944b4a15fb16f0da33e4e71b790815e2f88d49b5babf3b44a82d51a737422 aux/graph2smiles_runtime/utils/ctypes_calculator.py
|
| 15 |
+
7a671fbff8a4c202c33af82fe2708f848a4aa07526ef7d90536ff655c77700ef aux/graph2smiles_runtime/utils/data_utils.py
|
| 16 |
+
4b2c0587180c996e160581861b8c6dae0dfde8dc8fd0f4112bb0b07704a168b4 aux/graph2smiles_runtime/utils/parsing.py
|
| 17 |
+
0440ec0b6cee9da8e64b4397b83c6a1672ac3d134565c9aa7b758fd174c4fdf9 aux/graph2smiles_runtime/utils/preprocess_utils.py
|
| 18 |
+
50e105d0a95fab34653c0ddc134bda5324f5825b3ce907d6349183f34d38627d aux/graph2smiles_runtime/utils/rxn_graphs.py
|
| 19 |
+
5474b2518dceaaa121aef3e4656d808d3f1dc73161eff0139277bc7f0c021ab3 aux/graph2smiles_runtime/utils/train_utils.py
|
| 20 |
+
5553c34645ededd4e2012700cc0436ba54b061c3c7e97011e23b21c4eb05bfe8 aux/mar_files/handler.py
|
| 21 |
+
8d1d30921e14caa8bb1a4724026436f9450cf14d532b270e867e6c59888e5d06 aux/mar_files/models.zip
|
| 22 |
+
9309e0352e4fb7f6c00b8dccd1bd4300ed91f7660533e3ace9db8e61645caa26 aux/mar_files/predict.py
|
| 23 |
+
fb3b0374bcf3773e87926bce4160aa30bd9088e71b56b3daa617de2cb03892fa aux/mar_files/train.py
|
| 24 |
+
55202ac5081d1a26d19a7dc55cf112b4a94762f53f06e9cded8a4a81794b0eff aux/mar_files/utils.zip
|
| 25 |
+
d345fddee01220c978ebb7eb309603eb93f729c7f16138608b4fa3601be0af3d aux/mar_files/vocab.txt
|
| 26 |
+
56cac879f4f03d2a77cd1bffcc348082da1913257daa016f434835c5cbb63058 aux/mar_members.json
|
| 27 |
+
460d7fd212e36cd102514b591d81b886499780755438d47d5a62d24febd1246e aux/model_args.json
|
| 28 |
+
07c37c91ceb6a19eebabdd5b83315b7deceb4ff7c5a88dd41d76bf022c1a227c aux/safetensors_conversion.json
|
| 29 |
+
d345fddee01220c978ebb7eb309603eb93f729c7f16138608b4fa3601be0af3d aux/vocab.txt
|
| 30 |
+
89bbde98db91c67de993a5700eea47a250f1bddede31010905be22aa21ceeace benchmarks/default_test.jsonl
|
| 31 |
+
e10891de2a04dc3a7758ef20b50478c4f4285f4ac6c81f2f1ecc430e2ffb373d benchmarks/metadata.json
|
| 32 |
+
ed9665577446765da24e2552608d92aed552388c9b034bb7a03f5c2cccbb0c1b benchmarks/native/src-test.txt
|
| 33 |
+
57946e791815452a278ed93481aea629567372c79216895b30463e220b35f830 benchmarks/native/tgt-test.txt
|
| 34 |
+
bdf9cd84ef69476e6104267a1325fd431143c91a12adabf47c0b8d9fb2732560 manifest.json
|
| 35 |
+
76747c458b6703068a4b54fbb2c7defd7a23e60ab37fa39a97d37b3b26cc725e model.safetensors
|
| 36 |
+
9f15f2c00c40ad3b874eb810b5e339f5db51d2c327dc0bcdd808c408a01e1406 provenance.json
|
| 37 |
+
cb113b97332e3586b7acc3df01d767d9976ee13044b6381171783aa45c1ca3af wrapper_config.json
|
checkpoints/askcos_retro_graph2smiles/uspto_full/manifest.json
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"auxiliary_files": [
|
| 3 |
+
"aux/MAR-INF/MANIFEST.json",
|
| 4 |
+
"aux/checkpoint_metadata.json",
|
| 5 |
+
"aux/graph2smiles_runtime/models/attention_xl.py",
|
| 6 |
+
"aux/graph2smiles_runtime/models/dgat.py",
|
| 7 |
+
"aux/graph2smiles_runtime/models/dgcn.py",
|
| 8 |
+
"aux/graph2smiles_runtime/models/graph2smiles.py",
|
| 9 |
+
"aux/graph2smiles_runtime/models/graphfeat.py",
|
| 10 |
+
"aux/graph2smiles_runtime/models/model_utils.py",
|
| 11 |
+
"aux/graph2smiles_runtime/models/transformer_decoder.py",
|
| 12 |
+
"aux/graph2smiles_runtime/predict.py",
|
| 13 |
+
"aux/graph2smiles_runtime/train.py",
|
| 14 |
+
"aux/graph2smiles_runtime/utils/c_calculate.so",
|
| 15 |
+
"aux/graph2smiles_runtime/utils/chem_utils.py",
|
| 16 |
+
"aux/graph2smiles_runtime/utils/ctypes_calculator.py",
|
| 17 |
+
"aux/graph2smiles_runtime/utils/data_utils.py",
|
| 18 |
+
"aux/graph2smiles_runtime/utils/parsing.py",
|
| 19 |
+
"aux/graph2smiles_runtime/utils/preprocess_utils.py",
|
| 20 |
+
"aux/graph2smiles_runtime/utils/rxn_graphs.py",
|
| 21 |
+
"aux/graph2smiles_runtime/utils/train_utils.py",
|
| 22 |
+
"aux/mar_files/handler.py",
|
| 23 |
+
"aux/mar_files/models.zip",
|
| 24 |
+
"aux/mar_files/predict.py",
|
| 25 |
+
"aux/mar_files/train.py",
|
| 26 |
+
"aux/mar_files/utils.zip",
|
| 27 |
+
"aux/mar_files/vocab.txt",
|
| 28 |
+
"aux/mar_members.json",
|
| 29 |
+
"aux/model_args.json",
|
| 30 |
+
"aux/safetensors_conversion.json",
|
| 31 |
+
"aux/vocab.txt",
|
| 32 |
+
"benchmarks/default_test.jsonl",
|
| 33 |
+
"benchmarks/metadata.json",
|
| 34 |
+
"benchmarks/native/src-test.txt",
|
| 35 |
+
"benchmarks/native/tgt-test.txt"
|
| 36 |
+
],
|
| 37 |
+
"benchmark_datasets": [
|
| 38 |
+
{
|
| 39 |
+
"benchmark_variant": "askcos_uspto_full_r_smiles_compatibility_view",
|
| 40 |
+
"dataset_id": "askcos_retro_graph2smiles_uspto_full_uspto_full_test",
|
| 41 |
+
"dataset_ref": "uspto_full_gln",
|
| 42 |
+
"default": true,
|
| 43 |
+
"format": "jsonl",
|
| 44 |
+
"metadata_path": "benchmarks/metadata.json",
|
| 45 |
+
"native_input_format": "tokenized_parallel_txt",
|
| 46 |
+
"native_source_paths": [
|
| 47 |
+
"benchmarks/native/src-test.txt",
|
| 48 |
+
"benchmarks/native/tgt-test.txt"
|
| 49 |
+
],
|
| 50 |
+
"notes": [
|
| 51 |
+
"ASKCOS does not redistribute a native USPTO-FULL benchmark CSV with this TorchServe archive in datasets/modelos_ASKCOS.",
|
| 52 |
+
"This bundle uses the public R-SMILES/GLN USPTO-FULL tokenized test split as a redistribution-safe compatibility view.",
|
| 53 |
+
"benchmarks/default_test.jsonl collapses the contiguous augmentation factor of 5 back to one benchmark case per underlying reaction."
|
| 54 |
+
],
|
| 55 |
+
"num_examples": 96023,
|
| 56 |
+
"path": "benchmarks/default_test.jsonl",
|
| 57 |
+
"split": "test"
|
| 58 |
+
}
|
| 59 |
+
],
|
| 60 |
+
"checkpoint_id": "uspto_full",
|
| 61 |
+
"contained_artifact_bindings": [
|
| 62 |
+
{
|
| 63 |
+
"canonical_split_family": "askcos_uspto_full_split_unspecified",
|
| 64 |
+
"dataset_ref": "askcos_uspto_full_release",
|
| 65 |
+
"path": "modelos_ASKCOS/USPTO_FULL_new.mar",
|
| 66 |
+
"stage": "released_torchserve_archive"
|
| 67 |
+
}
|
| 68 |
+
],
|
| 69 |
+
"conversion": {
|
| 70 |
+
"converted_at": "1970-01-01T00:00:00+00:00",
|
| 71 |
+
"notes": [
|
| 72 |
+
"The upstream ASKCOS TorchServe .mar was unpacked into native bundle assets.",
|
| 73 |
+
"Tensor weights are stored canonically as model.safetensors; non-tensor runtime assets are stored under aux/.",
|
| 74 |
+
"The original .mar archive is not required for wrapper inference."
|
| 75 |
+
],
|
| 76 |
+
"safetensors": {
|
| 77 |
+
"format": "safetensors",
|
| 78 |
+
"num_tensors": 297,
|
| 79 |
+
"path": "model.safetensors",
|
| 80 |
+
"roundtrip_tensor_equal": true,
|
| 81 |
+
"runtime_assets": {
|
| 82 |
+
"checkpoint_metadata": "aux/checkpoint_metadata.json",
|
| 83 |
+
"model_args": "aux/model_args.json",
|
| 84 |
+
"runtime_source_dir": "aux/graph2smiles_runtime",
|
| 85 |
+
"vocab": "aux/vocab.txt"
|
| 86 |
+
},
|
| 87 |
+
"source_member": "model.pt",
|
| 88 |
+
"status": "converted"
|
| 89 |
+
},
|
| 90 |
+
"source_format": "torchserve_mar_embedded_checkpoint",
|
| 91 |
+
"status": "converted",
|
| 92 |
+
"tool_version": "initial"
|
| 93 |
+
},
|
| 94 |
+
"display_name": "ASKCOS Retro Graph2SMILES USPTO_FULL",
|
| 95 |
+
"embedding_supported": false,
|
| 96 |
+
"fine_tuning": {
|
| 97 |
+
"adapter_overlay_dir": "adapters",
|
| 98 |
+
"base_weights_path": "model.safetensors",
|
| 99 |
+
"notes": [
|
| 100 |
+
"This package preserves immutable base weights in model.safetensors and reserves adapters/ for future fine-tuning or LoRA overlays."
|
| 101 |
+
]
|
| 102 |
+
},
|
| 103 |
+
"format_version": 1,
|
| 104 |
+
"generated_at": "1970-01-01T00:00:00+00:00",
|
| 105 |
+
"input_schema": {
|
| 106 |
+
"product_field": "smiles",
|
| 107 |
+
"request_format": {
|
| 108 |
+
"smiles": [
|
| 109 |
+
"product_smiles"
|
| 110 |
+
]
|
| 111 |
+
},
|
| 112 |
+
"target_field": "reactants"
|
| 113 |
+
},
|
| 114 |
+
"model_id": "askcos_retro_graph2smiles",
|
| 115 |
+
"normalized_checkpoint_id": "uspto_full",
|
| 116 |
+
"package_layout": {
|
| 117 |
+
"adapters_dir": "adapters",
|
| 118 |
+
"aux_dir": "aux",
|
| 119 |
+
"benchmarks_dir": "benchmarks",
|
| 120 |
+
"weights_path": "model.safetensors"
|
| 121 |
+
},
|
| 122 |
+
"source_registry_refs": [
|
| 123 |
+
{
|
| 124 |
+
"checkpoint_id": "uspto_full",
|
| 125 |
+
"model_id": "askcos_retro_graph2smiles"
|
| 126 |
+
}
|
| 127 |
+
],
|
| 128 |
+
"split_provenance": [
|
| 129 |
+
{
|
| 130 |
+
"canonical_split_family": "askcos_uspto_full_split_unspecified",
|
| 131 |
+
"dataset_ref": "askcos_uspto_full_release",
|
| 132 |
+
"split_names": [],
|
| 133 |
+
"stage": "released_torchserve_archive"
|
| 134 |
+
},
|
| 135 |
+
{
|
| 136 |
+
"canonical_split_family": "askcos_uspto_full_split_unspecified",
|
| 137 |
+
"dataset_ref": "askcos_uspto_full_release",
|
| 138 |
+
"path": "modelos_ASKCOS/USPTO_FULL_new.mar",
|
| 139 |
+
"stage": "released_torchserve_archive"
|
| 140 |
+
}
|
| 141 |
+
],
|
| 142 |
+
"task_direction": "retrosynthesis",
|
| 143 |
+
"training_dataset_refs": [
|
| 144 |
+
"askcos_uspto_full_release"
|
| 145 |
+
],
|
| 146 |
+
"training_stage_bindings": [
|
| 147 |
+
{
|
| 148 |
+
"canonical_split_family": "askcos_uspto_full_split_unspecified",
|
| 149 |
+
"dataset_ref": "askcos_uspto_full_release",
|
| 150 |
+
"split_names": [],
|
| 151 |
+
"stage": "released_torchserve_archive"
|
| 152 |
+
},
|
| 153 |
+
{
|
| 154 |
+
"canonical_split_family": "askcos_uspto_full_split_unspecified",
|
| 155 |
+
"dataset_ref": "askcos_uspto_full_release",
|
| 156 |
+
"path": "modelos_ASKCOS/USPTO_FULL_new.mar",
|
| 157 |
+
"stage": "released_torchserve_archive"
|
| 158 |
+
}
|
| 159 |
+
],
|
| 160 |
+
"weights": {
|
| 161 |
+
"dtype_summary": "float tensors preserved from upstream checkpoint",
|
| 162 |
+
"framework": "pytorch",
|
| 163 |
+
"path": "model.safetensors",
|
| 164 |
+
"tensor_namespace": "askcos_graph2smiles"
|
| 165 |
+
},
|
| 166 |
+
"wrapper_config": "wrapper_config.json",
|
| 167 |
+
"wrapper_family": "askcos_graph2smiles"
|
| 168 |
+
}
|
checkpoints/askcos_retro_graph2smiles/uspto_full/provenance.json
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"conversion_notes": [
|
| 3 |
+
"The ASKCOS TorchServe .mar source archive was unpacked; model.mar is not copied into the normalized package.",
|
| 4 |
+
"Embedded tensor weights were serialized to model.safetensors and verified by safetensors round-trip equality.",
|
| 5 |
+
"Required non-tensor runtime assets such as templates, vocabularies, model args, OpenNMT metadata, and Graph2SMILES source support files are copied under aux/.",
|
| 6 |
+
"Lightweight MAR metadata is retained under aux/ for provenance only."
|
| 7 |
+
],
|
| 8 |
+
"copied_sidecars": [
|
| 9 |
+
"aux/MAR-INF/MANIFEST.json",
|
| 10 |
+
"aux/checkpoint_metadata.json",
|
| 11 |
+
"aux/graph2smiles_runtime/models/attention_xl.py",
|
| 12 |
+
"aux/graph2smiles_runtime/models/dgat.py",
|
| 13 |
+
"aux/graph2smiles_runtime/models/dgcn.py",
|
| 14 |
+
"aux/graph2smiles_runtime/models/graph2smiles.py",
|
| 15 |
+
"aux/graph2smiles_runtime/models/graphfeat.py",
|
| 16 |
+
"aux/graph2smiles_runtime/models/model_utils.py",
|
| 17 |
+
"aux/graph2smiles_runtime/models/transformer_decoder.py",
|
| 18 |
+
"aux/graph2smiles_runtime/predict.py",
|
| 19 |
+
"aux/graph2smiles_runtime/train.py",
|
| 20 |
+
"aux/graph2smiles_runtime/utils/c_calculate.so",
|
| 21 |
+
"aux/graph2smiles_runtime/utils/chem_utils.py",
|
| 22 |
+
"aux/graph2smiles_runtime/utils/ctypes_calculator.py",
|
| 23 |
+
"aux/graph2smiles_runtime/utils/data_utils.py",
|
| 24 |
+
"aux/graph2smiles_runtime/utils/parsing.py",
|
| 25 |
+
"aux/graph2smiles_runtime/utils/preprocess_utils.py",
|
| 26 |
+
"aux/graph2smiles_runtime/utils/rxn_graphs.py",
|
| 27 |
+
"aux/graph2smiles_runtime/utils/train_utils.py",
|
| 28 |
+
"aux/mar_files/handler.py",
|
| 29 |
+
"aux/mar_files/models.zip",
|
| 30 |
+
"aux/mar_files/predict.py",
|
| 31 |
+
"aux/mar_files/train.py",
|
| 32 |
+
"aux/mar_files/utils.zip",
|
| 33 |
+
"aux/mar_files/vocab.txt",
|
| 34 |
+
"aux/mar_members.json",
|
| 35 |
+
"aux/model_args.json",
|
| 36 |
+
"aux/safetensors_conversion.json",
|
| 37 |
+
"aux/vocab.txt"
|
| 38 |
+
],
|
| 39 |
+
"inner_members": [
|
| 40 |
+
{
|
| 41 |
+
"archive_path": "datasets/modelos_ASKCOS/USPTO_FULL_new.mar",
|
| 42 |
+
"member": "models.zip",
|
| 43 |
+
"role": "archive_member"
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
"archive_path": "datasets/modelos_ASKCOS/USPTO_FULL_new.mar",
|
| 47 |
+
"member": "predict.py",
|
| 48 |
+
"role": "archive_member"
|
| 49 |
+
},
|
| 50 |
+
{
|
| 51 |
+
"archive_path": "datasets/modelos_ASKCOS/USPTO_FULL_new.mar",
|
| 52 |
+
"member": "handler.py",
|
| 53 |
+
"role": "archive_member"
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"archive_path": "datasets/modelos_ASKCOS/USPTO_FULL_new.mar",
|
| 57 |
+
"member": "vocab.txt",
|
| 58 |
+
"role": "archive_member"
|
| 59 |
+
},
|
| 60 |
+
{
|
| 61 |
+
"archive_path": "datasets/modelos_ASKCOS/USPTO_FULL_new.mar",
|
| 62 |
+
"member": "train.py",
|
| 63 |
+
"role": "archive_member"
|
| 64 |
+
},
|
| 65 |
+
{
|
| 66 |
+
"archive_path": "datasets/modelos_ASKCOS/USPTO_FULL_new.mar",
|
| 67 |
+
"member": "model.pt",
|
| 68 |
+
"role": "weights_source"
|
| 69 |
+
},
|
| 70 |
+
{
|
| 71 |
+
"archive_path": "datasets/modelos_ASKCOS/USPTO_FULL_new.mar",
|
| 72 |
+
"member": "utils.zip",
|
| 73 |
+
"role": "archive_member"
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"archive_path": "datasets/modelos_ASKCOS/USPTO_FULL_new.mar",
|
| 77 |
+
"member": "MAR-INF/MANIFEST.json",
|
| 78 |
+
"role": "torchserve_manifest"
|
| 79 |
+
}
|
| 80 |
+
],
|
| 81 |
+
"normalized_checkpoint_id": "uspto_full",
|
| 82 |
+
"source_artifacts": [
|
| 83 |
+
{
|
| 84 |
+
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/modelos_ASKCOS/USPTO_FULL_new.mar",
|
| 85 |
+
"kind": "local_repo_file",
|
| 86 |
+
"path": "datasets/modelos_ASKCOS/USPTO_FULL_new.mar",
|
| 87 |
+
"role": "source_artifact",
|
| 88 |
+
"sha256": "a59fa4e3d57a8f08a934af9c3569f07f42c052a871f0e9abccad26b3e4f0841c",
|
| 89 |
+
"size": 200532708
|
| 90 |
+
},
|
| 91 |
+
{
|
| 92 |
+
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/modelos_ASKCOS/download_trained_models.sh",
|
| 93 |
+
"kind": "local_repo_file",
|
| 94 |
+
"path": "datasets/modelos_ASKCOS/download_trained_models.sh",
|
| 95 |
+
"role": "source_artifact",
|
| 96 |
+
"sha256": "e88d26f86ce79d2c7d8f05d1a59e3b1b88bde69c3afb95d065c932ff058092be",
|
| 97 |
+
"size": 2374
|
| 98 |
+
},
|
| 99 |
+
{
|
| 100 |
+
"absolute_path": "/home/ian-l/lucai/syntheseus-bundle-builder/datasets/modelos_ASKCOS/download_trained_models2.sh",
|
| 101 |
+
"kind": "local_repo_file",
|
| 102 |
+
"path": "datasets/modelos_ASKCOS/download_trained_models2.sh",
|
| 103 |
+
"role": "source_artifact",
|
| 104 |
+
"sha256": "c2351dd12f68b0f372b23183cf470fa643f73274f66e34dfc0dacd1ce1a9843e",
|
| 105 |
+
"size": 1234
|
| 106 |
+
}
|
| 107 |
+
]
|
| 108 |
+
}
|
checkpoints/askcos_retro_graph2smiles/uspto_full/wrapper_config.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architecture_class": "Graph2SMILES",
|
| 3 |
+
"device_supported": [
|
| 4 |
+
"cpu",
|
| 5 |
+
"cuda"
|
| 6 |
+
],
|
| 7 |
+
"fine_tuning": {
|
| 8 |
+
"adapter_overlay_dir": "adapters",
|
| 9 |
+
"base_weights_path": "model.safetensors",
|
| 10 |
+
"notes": [
|
| 11 |
+
"Base weights stay immutable in model.safetensors; future fine-tuning or LoRA adapters should be added as overlays under adapters/."
|
| 12 |
+
]
|
| 13 |
+
},
|
| 14 |
+
"input_schema": {
|
| 15 |
+
"product_field": "smiles",
|
| 16 |
+
"request_format": {
|
| 17 |
+
"smiles": [
|
| 18 |
+
"product_smiles"
|
| 19 |
+
]
|
| 20 |
+
},
|
| 21 |
+
"target_field": "reactants"
|
| 22 |
+
},
|
| 23 |
+
"license": "mit",
|
| 24 |
+
"loader": {
|
| 25 |
+
"checkpoint_metadata": "aux/checkpoint_metadata.json",
|
| 26 |
+
"kind": "askcos_graph2smiles_safetensors",
|
| 27 |
+
"model_args": "aux/model_args.json",
|
| 28 |
+
"model_version": "1.0",
|
| 29 |
+
"runtime_source_dir": "aux/graph2smiles_runtime",
|
| 30 |
+
"served_model_name": "USPTO_full",
|
| 31 |
+
"source_handler": "handler.py",
|
| 32 |
+
"state_dict_format": "safetensors",
|
| 33 |
+
"vocab": "aux/vocab.txt"
|
| 34 |
+
},
|
| 35 |
+
"package_layout": {
|
| 36 |
+
"adapters_dir": "adapters",
|
| 37 |
+
"aux_dir": "aux",
|
| 38 |
+
"weights_path": "model.safetensors"
|
| 39 |
+
},
|
| 40 |
+
"runtime_file_map": {
|
| 41 |
+
"aux/checkpoint_metadata.json": "aux/checkpoint_metadata.json",
|
| 42 |
+
"aux/graph2smiles_runtime": "aux/graph2smiles_runtime",
|
| 43 |
+
"aux/model_args.json": "aux/model_args.json",
|
| 44 |
+
"aux/vocab.txt": "aux/vocab.txt",
|
| 45 |
+
"model.safetensors": "model.safetensors"
|
| 46 |
+
},
|
| 47 |
+
"task_direction": "retrosynthesis",
|
| 48 |
+
"wrapper_family": "askcos_graph2smiles"
|
| 49 |
+
}
|