File size: 1,432 Bytes
ccf682e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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