Skip to content

Commit 94fb33c

Browse files
authored
Merge pull request #36 from dhruvdcoder/dhruvesh/LLMs
The enormous PR to support larger DLMs and a minimal eval harness
2 parents 5f0ce0a + b5a91fb commit 94fb33c

86 files changed

Lines changed: 7784 additions & 1735 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.cursor/rules/conda-env.mdc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
description: Always use the project conda env for Python / pip / pytest in xlm-core
3+
alwaysApply: true
4+
---
5+
6+
# xlm-core conda environment
7+
8+
This workspace has a dedicated conda env. **Always activate it before running
9+
Python, `pip`, `pytest`, or any tool that imports from the project.**
10+
11+
```bash
12+
conda activate /scratch3/workspace/dhruveshpate_umass_edu-idlm/xlm-core/.venv_xlm_core
13+
```
14+
15+
Do **not** fall back to system Python (`/usr/bin/python`) or `pip install
16+
--break-system-packages`; PEP 668 will block it and packages won't be visible
17+
to the project. Do **not** create ad-hoc venvs in the workspace.
18+
19+
## Concrete patterns
20+
21+
```bash
22+
# ❌ BAD — system python, packages won't reach the project env
23+
python3 -m pip install cairosvg
24+
pip install --user --break-system-packages cairosvg
25+
pytest tests/
26+
27+
# ✅ GOOD — activate first, then run normally
28+
conda activate /scratch3/workspace/dhruveshpate_umass_edu-idlm/xlm-core/.venv_xlm_core
29+
pip install cairosvg
30+
pytest tests/
31+
```
32+
33+
For one-off shell calls where activation state may not persist, prefix
34+
explicitly:
35+
36+
```bash
37+
# ✅ GOOD — single-shot invocation without relying on shell state
38+
/scratch3/workspace/dhruveshpate_umass_edu-idlm/xlm-core/.venv_xlm_core/bin/python -m pytest tests/
39+
/scratch3/workspace/dhruveshpate_umass_edu-idlm/xlm-core/.venv_xlm_core/bin/pip install cairosvg
40+
```
41+
42+
## Verifying you're in the right env
43+
44+
```bash
45+
which python # should print .../.venv_xlm_core/bin/python
46+
python -c "import sys; print(sys.prefix)"
47+
```

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Install dependencies
2121
run: |
2222
python -m pip install --upgrade pip
23-
pip install -e .
23+
pip install -e ".[all]"
2424
pip install -e xlm-models/
2525
pip install -r requirements/test_requirements.txt
2626

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ site
4747
.cursorindexingignore
4848
oracle/fpscores.pkl
4949
.cursor/plans
50+
src/xlm/backbones/dream_on
5051

5152
# protein eval — generated artifacts and eval venvs
5253
vendor/dplm/.venv-esmfold/
5354
evals/protein_eval/*/esmfold_pdb/
5455
evals/protein_eval/*/metrics.jsonl
5556
evals/protein_eval/logs/
5657
.pytest_cache/
57-
docs/**/linkedin
58+
docs/**/linkedin

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include requirements.txt
2+
recursive-include requirements *.txt

PR_MESSAGE_SAFE.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Consolidate SAFE / molgen task code in `xlm.tasks.safe_molgen`
2+
3+
## Motivation
4+
5+
- Single canonical module for SAFE bracket encoding, fragment preprocessing, and post-hoc evaluators (`DeNovoEval`, `FragmentEval`). Deprecated TorchMetrics molgen training metrics were **not** carried forward.
6+
- Align FlexMDM configs and lightning_train SAFE datasets with the learned-noise pipeline (fragment infill, logging fields, checkpoint cadence where copied).
7+
- Remove `src/xlm/tasks/molgen.py` so there is no duplicate or shim layer.
8+
9+
## What changed
10+
11+
### Python
12+
13+
- **Added** [`src/xlm/tasks/safe_molgen.py`](src/xlm/tasks/safe_molgen.py): based on learned-noise `molgen_new.py` (GenMol-aligned `BracketSAFEConverter`, FCD hooks, grouped `FragmentEval`, etc.). Module name avoids clashing with the PyPI **`safe`** package.
14+
- **Deleted** [`src/xlm/tasks/molgen.py`](src/xlm/tasks/molgen.py).
15+
- **Removed** deprecated TorchMetrics path: no `MolGenMetric` / `molgen_update_fn` in `safe_molgen.py`; deleted `src/xlm/configs/lightning_train/metrics/molgen.yaml`. Use **`post_hoc_evaluator`** + `DeNovoEval` / `FragmentEval` for molecule metrics.
16+
17+
### Configs (Hydra)
18+
19+
- **Copied / updated** from learned-noise:
20+
- `xlm-models/flexmdm/configs/experiment/safe_flexmdm.yaml`, `safe_flexmdm_fragment.yaml`
21+
- `xlm-models/flexmdm/configs/datamodule/safe_flexmdm.yaml`, `safe_flexmdm_fragment.yaml`
22+
- `src/xlm/configs/lightning_train/datamodule/safe_fragment.yaml`
23+
- `src/xlm/configs/lightning_train/datasets/safe_fragment_test.yaml`, `safe_fragment_val.yaml`
24+
- `datasets/safe.yaml`, `safe_train.yaml`, `safe_val.yaml`, `safe_test.yaml`
25+
- `tokenizer/safe.yaml`, `post_hoc_evaluator/denovo.yaml`
26+
- **Retargeted** all `xlm.tasks.molgen` / `xlm.tasks.molgen_new` references to **`xlm.tasks.safe_molgen`** (including `qm9_flexmdm` post-hoc evaluator).
27+
- **Fixed** `safe_flexmdm_fragment` datamodule `print_batch_fn`: `lflexmdm...`**`flexmdm.datamodule_flexmdm.print_batch_flexmdm`**.
28+
29+
### Requirements
30+
31+
- Comment update in [`requirements/molgen_requirements.txt`](requirements/molgen_requirements.txt) (datamol note refers to `xlm.tasks.safe_molgen`). Dependency set already matched learned-noise (`datamol`, `torch_fcd`, `fcd`, etc.); `datasets` remains on core install.
32+
33+
## Config migration cheat sheet
34+
35+
| Old | New |
36+
|-----|-----|
37+
| `xlm.tasks.molgen.*` | `xlm.tasks.safe_molgen.*` |
38+
| `xlm.tasks.molgen_new.*` | `xlm.tasks.safe_molgen.*` |
39+
| `xlm.tasks.safe.*` (internal task module; clashes with PyPI `safe`) | `xlm.tasks.safe_molgen.*` |
40+
41+
Unchanged: YAML keys such as **`molgen_task_name`** (task selector, not a Python module).
42+
43+
## Verification
44+
45+
- `python -m py_compile src/xlm/tasks/safe_molgen.py` (passes).
46+
- Full import test requires a molgen-capable env (`torch`, `rdkit`, `safe-mol`, `datamol`, `pytdc`, …). Example:
47+
48+
```bash
49+
conda activate /scratch3/workspace/dhruveshpate_umass_edu-idlm/xlm-core/.venv_xlm_core # or your env
50+
cd xlm-core && PYTHONPATH=src python -c "from xlm.tasks.safe_molgen import DeNovoEval, FragmentEval"
51+
```
52+
53+
- Recommended: Hydra compose training config with `experiment=safe_flexmdm` and `experiment=safe_flexmdm_fragment` once `flexmdm` is on the Hydra search path (`xlm-models` discovery).
54+
55+
## Follow-ups
56+
57+
- Delete this file before or after merge if you do not want it in the repo long term.
58+
- Watch for downstream repos that imported `xlm.tasks.molgen` in Python code (xlm-core YAMLs are updated; external callers must switch to `xlm.tasks.safe_molgen`).

requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ hydra-submitit-launcher
99
datasets >= 3.3.2, < 4.0.0
1010
wandb
1111
transformers
12+
regex
1213
more-itertools
1314
torchdata>=0.9.0
1415
rich
@@ -19,4 +20,5 @@ torch-ema
1920
pydot
2021
tabulate
2122
pandas
22-
simple_slurm
23+
simple_slurm
24+
math-verify

requirements/llm_eval.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
math-verify[antlr4_9_3]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Requirements for Molecule Generation. Largely based on GenMol: https://github.com/NVIDIA-Digital-Bio/genmol/blob/main/env/requirements.txt
2+
# Optional heavyweight install via setuptools extra: pip install "xlm-core[molgen]"
3+
# Lightweight SAFE stack without Biomemo: pip install "xlm-core[safe]"
4+
# bionemo sub-packages
5+
bionemo-moco>=0.0.2.1
6+
7+
# external dependencies
8+
#torch==2.6.0
9+
#numpy==1.26.4
10+
jaxtyping>=0.2.34
11+
pot>=0.9.5
12+
# scikit-learn==1.2.2 install this after due to soft bionemo-moco conflict
13+
einops
14+
pandas
15+
safe-mol==0.1.14
16+
datamol # BracketSAFEConverter in xlm.tasks.safe_molgen uses datamol with safe.converter.SAFEConverter
17+
pytdc==0.4.1
18+
easydict
19+
openbabel-wheel==3.1.1.22
20+
rdkit
21+
# PyTorch FCD backend (import path: fcd_torch); PyPI distribution is hyphenated:
22+
fcd-torch
23+
fcd
24+
transformers==4.57.1 # other versions may not work.
25+
setuptools<82.0.0
26+
#numpy==1.26.4

requirements/safe_extra.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Pinned SAFE / cheminformatics stack pulled from requirements/molgen_requirements.txt
2+
# Install: pip install "xlm-core[safe]"
3+
safe-mol==0.1.14
4+
datamol
5+
rdkit
6+
pytdc==0.4.1

setup.py

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,44 @@
99

1010
PATH_ROOT = os.path.dirname(__file__)
1111

12+
1213
def load_requirements(
1314
path_dir: str = PATH_ROOT, comment_char: str = "#"
1415
) -> List:
1516
with open(os.path.join(path_dir, "requirements.txt"), "r") as file:
1617
reqs = [ln.strip() for ln in file.readlines()]
1718
return reqs
1819

20+
21+
def load_requirements_optional(relative_filename: str) -> List[str]:
22+
"""Extras list for setuptools (strip blanks and inline ``#`` comments)."""
23+
path = os.path.join(PATH_ROOT, relative_filename)
24+
with open(path, "r") as file:
25+
lines = file.readlines()
26+
reqs = []
27+
for ln in lines:
28+
s = ln.split("#")[0].strip()
29+
if s:
30+
reqs.append(s)
31+
return reqs
32+
33+
1934
install_requires = load_requirements()
2035

36+
_safe_reqs = load_requirements_optional("requirements/safe_extra.txt")
37+
_molgen_reqs = load_requirements_optional("requirements/molgen_requirements.txt")
38+
_llm_eval_reqs = load_requirements_optional("requirements/llm_eval.txt")
39+
40+
extras_require = {
41+
"safe": _safe_reqs,
42+
"molgen": _molgen_reqs,
43+
"llm_eval": _llm_eval_reqs,
44+
"all": list(
45+
dict.fromkeys(_safe_reqs + _molgen_reqs + _llm_eval_reqs),
46+
),
47+
}
48+
49+
2150
setup(
2251
name="xlm-core",
2352
version=VERSION["VERSION"],
@@ -31,25 +60,30 @@ def load_requirements(
3160
"tests",
3261
],
3362
),
34-
description='XLM Framework',
63+
description="XLM Framework",
3564
long_description="""
3665
XLM is a unified framework for developing and comparing small non-autoregressive language models. It uses PyTorch as the deep learning framework, PyTorch Lightning for training utilities, and Hydra for configuration management. XLM provides core components for flexible data handling and training, useful architectural implementations for non-autoregressive workflows, and support for arbitrary runtime code injection. Custom model implementations that leverage the core components of xlm can be found in the xlm-models package. The package also includes a few preconfigured synthetic planning and language-modeling datasets.
3766
3867
Usage:
3968
pip install xlm-core
40-
41-
Command usage:
69+
pip install "xlm-core[safe]" # optional: SAFE molecule preprocessing / evaluators
70+
pip install "xlm-core[molgen]" # optional: fuller GenMol / Biomemo stack (molgen_requirements.txt)
71+
pip install "xlm-core[llm_eval]" # optional: ANTLR build of math-verify (LLM benchmarks)
72+
pip install "xlm-core[all]" # union of safe + molgen + llm_eval (used in CI)
4273
xlm job_type=[JOB_TYPE] job_name=[JOB_NAME] experiment=[CONFIG_PATH]
4374
4475
The job_type argument can be one of train ,eval and generate. The experiment argument should point to the root hydra config file.
4576
""",
46-
install_requires = install_requires,
47-
project_urls={
48-
"Source Code": "https://github.com/dhruvdcoder/xlm-core"
49-
},
77+
install_requires=install_requires,
78+
extras_require=extras_require,
79+
project_urls={"Source Code": "https://github.com/dhruvdcoder/xlm-core"},
5080
package_dir={"": "src"},
5181
package_data={
52-
"xlm": ["configs/**/*.yaml", "configs/**/*.yml"],
82+
"xlm": [
83+
"configs/**/*.yaml",
84+
"configs/**/*.yml",
85+
"src/xlm/tasks/zinc_len.pkl",
86+
],
5387
},
5488
keywords=[
5589
"AI",
@@ -63,7 +97,7 @@ def load_requirements(
6397
"console_scripts": [
6498
"xlm=xlm.__main__:main",
6599
"xlm-scaffold=xlm.commands.scaffold_model:main",
66-
"xlm-push-to-hub=xlm.commands.push_to_hub:main"
100+
"xlm-push-to-hub=xlm.commands.push_to_hub:main",
67101
],
68102
},
69103
python_requires=">=3.11",

0 commit comments

Comments
 (0)