Skip to main content

    Troubleshooting DeepPurpose

    Fix DeepPurpose installs, DGL and RDKit imports, CUDA device errors, out-of-memory training runs, SMILES parsing failures and diverging loss or NaNs.

    DeepPurpose is a deep learning library for drug-target interaction (DTI) prediction. This guide covers common issues and their solutions.

    Installation issues

    ModuleNotFoundError: No module named 'DeepPurpose'

    Install DeepPurpose from pip or GitHub:

    pip install DeepPurpose
    
    # Or install from source for latest features
    pip install git+https://github.com/kexinhuang12345/DeepPurpose.git

    ImportError: DGL backend not set

    For GNN encoders (MPNN, DGL_*), install DGL:

    pip install dgl dgllife

    RDKit import errors

    RDKit is required for molecular processing:

    conda install -c conda-forge rdkit
    # Or via pip
    pip install rdkit

    Common issues

    CUDA error: invalid device ordinal

    Match torch to your CUDA runtime (e.g., cu121) and confirm torch.cuda.device_count() > 0. Set CUDA_VISIBLE_DEVICES if the job exposes multiple GPUs.

    import torch
    print(f"CUDA available: {torch.cuda.is_available()}")
    print(f"Device count: {torch.cuda.device_count()}")
    print(f"Current device: {torch.cuda.current_device()}")

    OOM (Out of Memory) during training

    Lower batch_size, shorten sequences (truncate SMILES/FASTA), and use simpler encoders to reduce memory:

    • Switch from Transformer to CNN encoders
    • Switch from GNN (MPNN, DGL_*) to fingerprint encoders (Morgan, Pubchem)
    • Reduce cls_hidden_dims layer sizes
    • Set train_epoch lower and use early stopping

    Data parsing errors

    Validate CSV columns (smiles, protein, affinity or task-specific labels). Remove empty strings and canonicalize SMILES before featurization:

    from rdkit import Chem
    
    def validate_smiles(smiles):
        """Check if SMILES is valid."""
        mol = Chem.MolFromSmiles(smiles)
        return mol is not None
    
    def canonicalize_smiles(smiles):
        """Canonicalize SMILES string."""
        mol = Chem.MolFromSmiles(smiles)
        if mol:
            return Chem.MolToSmiles(mol, canonical=True)
        return None

    Diverging loss / NaNs

    Reduce learning rate, disable weight decay for small datasets, and verify labels are scaled correctly for regression vs. classification tasks:

    • For binding affinity regression, use log-transformed values (pKd, pKi)
    • Ensure labels are in reasonable range (e.g., 0-15 for pKd)
    • Start with LR=0.0001 and increase gradually

    Encoder-specific issues

    GNN encoders fail on some molecules

    Some molecules may fail graph construction:

    # Filter molecules that fail DGL processing
    from dgllife.utils import smiles_to_bigraph, CanonicalAtomFeaturizer
    
    def check_gnn_compatible(smiles):
        try:
            graph = smiles_to_bigraph(smiles, node_featurizer=CanonicalAtomFeaturizer())
            return graph is not None
        except:
            return False
    
    valid_smiles = [s for s in smiles_list if check_gnn_compatible(s)]

    Transformer encoder slow on long sequences

    Transformer attention scales quadratically with sequence length. For long proteins:

    • Truncate sequences to max ~1000 amino acids
    • Use CNN encoder for long proteins
    • Consider domain-based splitting for multi-domain proteins

    Pretrained encoder loading fails

    Ensure you have the correct encoder name:

    # Available pretrained models
    from DeepPurpose import DTI as models
    model = models.model_pretrained(model='MPNN_CNN_BindingDB')
    # Options: MPNN_CNN_DAVIS, Morgan_CNN_BindingDB, etc.

    Logging checklist

    • Log DeepPurpose and torch versions, CUDA availability, and GPU name.
    • Capture the exact encoders used (drug_encoding, target_encoding).
    • Record dataset split fractions and random seeds.
    • Save a sample batch (first 5 rows) to outputs/sample_batch.csv for debugging.

    When to retry vs. stop

    • Retry: transient CUDA initialization failures or intermittent filesystem errors.
    • Stop and fix: missing columns, incompatible torch/CUDA versions, or consistent NaNs after lowering LR.

    Getting help

    If issues persist:

    1. Check the DeepPurpose GitHub Issues
    2. Reference the Bioinformatics paper for methodology details
    3. Ensure you're using compatible versions:
      • Python 3.7+
      • PyTorch 1.7+
      • RDKit 2020+
      • DGL 0.5+ (for GNN encoders)

    Was this page helpful?

    On this page

    On this page

    Loading...