Download train/CCFM/pca_emb/_bootstrap_scdfm.py from ethan1115/lfj-code: direct link, hf CLI and curl.
- Browser
- Download file 3.17 kB
-
https://huggingface.co/datasets/ethan1115/lfj-code/resolve/main/train/CCFM/pca_emb/_bootstrap_scdfm.py
- Command line
-
hf download hf://datasets/ethan1115/lfj-code/train/CCFM/pca_emb/_bootstrap_scdfm.py
-
curl -L -o _bootstrap_scdfm.py https://huggingface.co/datasets/ethan1115/lfj-code/resolve/main/train/CCFM/pca_emb/_bootstrap_scdfm.py
3.17 kB
| """ | |
| Bootstrap scDFM imports by creating missing __init__.py files and loading | |
| its modules under a 'scdfm_src' prefix in sys.modules. | |
| This module MUST be imported before any CCFM src imports. | |
| """ | |
| import sys | |
| import os | |
| import types | |
| _SCDFM_ROOT = os.path.normpath( | |
| os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "transfer", "code", "scDFM") | |
| ) | |
| # Directories in scDFM that need __init__.py to be proper packages | |
| _DIRS_NEEDING_INIT = [ | |
| "src", | |
| "src/models", | |
| "src/models/origin", | |
| "src/data_process", | |
| "src/tokenizer", | |
| "src/script", | |
| "src/models/perturbation", | |
| ] | |
| def _ensure_init_files(): | |
| """Create missing __init__.py files in scDFM so it can be imported as packages.""" | |
| created = [] | |
| for d in _DIRS_NEEDING_INIT: | |
| init_path = os.path.join(_SCDFM_ROOT, d, "__init__.py") | |
| if not os.path.exists(init_path): | |
| with open(init_path, "w") as f: | |
| f.write("# Auto-created by CCFM bootstrap\n") | |
| created.append(init_path) | |
| return created | |
| def bootstrap(): | |
| """Load scDFM's src package as 'scdfm_src' in sys.modules.""" | |
| if "scdfm_src" in sys.modules: | |
| return # Already bootstrapped | |
| # Create missing __init__.py files | |
| _ensure_init_files() | |
| # Save CCFM's src modules | |
| saved = {} | |
| for key in list(sys.modules.keys()): | |
| if key == "src" or key.startswith("src."): | |
| saved[key] = sys.modules.pop(key) | |
| # Add scDFM root to path | |
| sys.path.insert(0, _SCDFM_ROOT) | |
| try: | |
| # Import scDFM modules (their relative imports work now) | |
| import src as scdfm_src_pkg | |
| import src.models | |
| import src.models.origin | |
| import src.models.origin.blocks | |
| import src.models.origin.layers | |
| import src.models.origin.model | |
| import src.flow_matching | |
| import src.flow_matching.path | |
| import src.flow_matching.path.path | |
| import src.flow_matching.path.path_sample | |
| import src.flow_matching.path.affine | |
| import src.flow_matching.path.scheduler | |
| import src.flow_matching.path.scheduler.scheduler | |
| # Skip src.flow_matching.ot (requires 'ot' package, not needed for CCFM) | |
| import src.utils | |
| import src.utils.utils | |
| import src.tokenizer | |
| import src.tokenizer.gene_tokenizer | |
| # Skip src.data_process (has heavy deps like bs4, rdkit) | |
| # We handle data loading separately in CCFM | |
| # Re-register all under scdfm_src.* prefix | |
| for key in list(sys.modules.keys()): | |
| if key == "src" or key.startswith("src."): | |
| new_key = "scdfm_" + key | |
| sys.modules[new_key] = sys.modules[key] | |
| finally: | |
| # Remove scDFM's src.* entries | |
| for key in list(sys.modules.keys()): | |
| if (key == "src" or key.startswith("src.")) and not key.startswith("scdfm_"): | |
| del sys.modules[key] | |
| # Restore CCFM's src modules | |
| for key, mod in saved.items(): | |
| sys.modules[key] = mod | |
| # Remove scDFM from front of path | |
| if _SCDFM_ROOT in sys.path: | |
| sys.path.remove(_SCDFM_ROOT) | |
| bootstrap() | |