Merge pull request #8 from kashif/hub
[Hub] Download weights automatically from hub
This commit is contained in:
@@ -78,7 +78,7 @@ tfm = timesfm.TimesFm(
|
|||||||
model_dims=1280,
|
model_dims=1280,
|
||||||
backend=<backend>,
|
backend=<backend>,
|
||||||
)
|
)
|
||||||
tfm.load_from_checkpoint(<checkpoint_path>)
|
tfm.load_from_checkpoint(repo_id="google/timesfm-1.0-200m")
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that the four parameters are fixed to load the 200m model
|
Note that the four parameters are fixed to load the 200m model
|
||||||
|
|||||||
+11
-3
@@ -16,14 +16,16 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
from os import path
|
||||||
import time
|
import time
|
||||||
from typing import Any, Literal, Sequence
|
from typing import Any, Literal, Optional, Sequence
|
||||||
|
|
||||||
import einshape as es
|
import einshape as es
|
||||||
import jax
|
import jax
|
||||||
import jax.numpy as jnp
|
import jax.numpy as jnp
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
from huggingface_hub import snapshot_download
|
||||||
from paxml import checkpoints
|
from paxml import checkpoints
|
||||||
from paxml import tasks_lib
|
from paxml import tasks_lib
|
||||||
from praxis import base_hyperparams
|
from praxis import base_hyperparams
|
||||||
@@ -222,17 +224,23 @@ class TimesFm:
|
|||||||
|
|
||||||
def load_from_checkpoint(
|
def load_from_checkpoint(
|
||||||
self,
|
self,
|
||||||
checkpoint_path: str,
|
checkpoint_path: Optional[str] = None,
|
||||||
|
repo_id: str = "google/timesfm-1.0-200m",
|
||||||
checkpoint_type: checkpoints.CheckpointType = checkpoints.CheckpointType.FLAX,
|
checkpoint_type: checkpoints.CheckpointType = checkpoints.CheckpointType.FLAX,
|
||||||
step: int | None = None,
|
step: int | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Loads a checkpoint and compiles the decoder.
|
"""Loads a checkpoint and compiles the decoder.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
checkpoint_path: path to the checkpoint directory.
|
checkpoint_path: Optional path to the checkpoint directory.
|
||||||
|
repo_id: Hugging Face Hub repo id.
|
||||||
checkpoint_type: type of PAX checkpoint
|
checkpoint_type: type of PAX checkpoint
|
||||||
step: step of the checkpoint to load. If `None`, load latest checkpoint.
|
step: step of the checkpoint to load. If `None`, load latest checkpoint.
|
||||||
"""
|
"""
|
||||||
|
# Download the checkpoint from Hugging Face Hub if not given
|
||||||
|
if checkpoint_path is None:
|
||||||
|
checkpoint_path = path.join(snapshot_download(repo_id), "checkpoints")
|
||||||
|
|
||||||
# Initialize the model weights.
|
# Initialize the model weights.
|
||||||
self._logging("Constructing model weights.")
|
self._logging("Constructing model weights.")
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|||||||
Reference in New Issue
Block a user