| # modeling_matformer.py | |
| import os | |
| import sys | |
| matformer_root = os.getenv("MATFORMER_ROOT") | |
| if matformer_root: | |
| matformer_root = os.path.abspath(os.path.expanduser(matformer_root)) | |
| if matformer_root not in sys.path: | |
| sys.path.insert(0, matformer_root) | |
| try: | |
| from matformer.huggingface_integration import ( | |
| MatformerForCausalLM, | |
| MatformerForMaskedLM, | |
| MatformerForSequenceClassification, | |
| MatformerModel, | |
| MatformerConfig, | |
| register_matformer | |
| ) | |
| register_matformer() | |
| except ImportError as e: | |
| import subprocess | |
| import tempfile | |
| print("Installing Matformer from GitHub...") | |
| try: | |
| subprocess.check_call([ | |
| sys.executable, "-m", "pip", "install", | |
| "git+https://github.com/mrinaldi97/matformer.git" | |
| ]) | |
| from matformer.huggingface_integration import ( | |
| MatformerForCausalLM, | |
| MatformerForMaskedLM, | |
| MatformerForSequenceClassification, | |
| MatformerModel, | |
| MatformerConfig, | |
| register_matformer | |
| ) | |
| register_matformer() | |
| except Exception as install_error: | |
| raise ImportError( | |
| "Failed to install Matformer. Install manually:\n" | |
| " pip install git+https://github.com/mrinaldi97/matformer.git\n" | |
| "Or set MATFORMER_ROOT environment variable" | |
| ) from install_error | |