Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added weights_path to enable passing in weights file from pretraining #52

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions mtenn/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pydantic import BaseModel, Field, root_validator
import random
from typing import Callable, ClassVar
from pathlib import Path
import mtenn
import numpy as np
import torch
Expand Down Expand Up @@ -83,6 +84,9 @@ class ModelConfigBase(BaseModel):
# Model weights
model_weights: dict | None = Field(None, type=dict, description="Model weights.")

# Path to pretrained model weights (.th) file
weights_path: Path | None = Field(None, type=Path, description="Path to model weights file.")

# Shared parameters for MTENN
grouped: bool = Field(False, description="Model is a grouped (multi-pose) model.")
strategy: StrategyConfig = Field(
Expand Down Expand Up @@ -227,6 +231,10 @@ def build(self) -> mtenn.model.Model:
# Build the actual Model
model = self._build(mtenn_params)

# Load weights file
if self.weights_path and self.weights_path.exists():
self.model_weights = torch.load(self.weights_path)

# Set model weights
if self.model_weights:
model.load_state_dict(self.model_weights)
Expand Down
Loading