diff --git a/pvnet/models/base_model.py b/pvnet/models/base_model.py index b4a23d3d..eab47ccf 100644 --- a/pvnet/models/base_model.py +++ b/pvnet/models/base_model.py @@ -230,6 +230,7 @@ def save_pretrained( data_config: Optional[Union[str, Path]], repo_id: Optional[str] = None, push_to_hub: bool = False, + wandb_repo: Optional[str] = None, wandb_ids: Optional[Union[list[str], str]] = None, card_template_path=None, **kwargs, @@ -248,9 +249,10 @@ def save_pretrained( ID of your repository on the Hub. Used only if `push_to_hub=True`. Will default to the folder name if not provided. push_to_hub (`bool`, *optional*, defaults to `False`): - Whether or not to push your model to the Huggingface Hub after saving it. + Whether or not to push your model to the HuggingFace Hub after saving it. + wandb_repo: Identifier of the repo on wandb. wandb_ids: Identifier(s) of the model on wandb. - card_template_path: Path to the huggingface model card template. Defaults to card in + card_template_path: Path to the HuggingFace model card template. Defaults to card in PVNet library if set to None. kwargs: Additional key word arguments passed along to the @@ -277,11 +279,20 @@ def save_pretrained( # Taylor the data config to the model being saved minimize_data_config(new_data_config_path, new_data_config_path, self) + # Get appropriate model card + model_name = repo_id.split("/")[1] + if model_name == "windnet_india": + model_card = "wind_india_model_card_template.md" + elif model_name == "pvnet_india": + model_card = "pv_india_model_card_template.md" + else: + model_card = "pv_uk_regional_model_card_template.md" + # Creating and saving model card. card_data = ModelCardData(language="en", license="mit", library_name="pytorch") if card_template_path is None: card_template_path = ( - f"{os.path.dirname(os.path.abspath(__file__))}/model_card_template.md" + f"{os.path.dirname(os.path.abspath(__file__))}/model_cards/{model_card}" ) if isinstance(wandb_ids, str): @@ -289,7 +300,7 @@ def save_pretrained( wandb_links = "" for wandb_id in wandb_ids: - link = f"https://wandb.ai/openclimatefix/pvnet2.1/runs/{wandb_id}" + link = f"https://wandb.ai/{wandb_repo}/runs/{wandb_id}" wandb_links += f" - [{link}]({link})\n" card = ModelCard.from_template( diff --git a/pvnet/models/model_cards/pv_india_model_card_template.md b/pvnet/models/model_cards/pv_india_model_card_template.md new file mode 100644 index 00000000..4f16a3e8 --- /dev/null +++ b/pvnet/models/model_cards/pv_india_model_card_template.md @@ -0,0 +1,51 @@ +--- +{{ card_data }} +--- + + + + + + +# PVNet India + +## Model Description + + +This model class uses numerical weather predictions from providers such as ECMWF to forecast the PV power in North West India over the next 48 hours. More information can be found in the model repo [1] and experimental notes [here](https://github.com/openclimatefix/PVNet/tree/main/experiments/india). + + +- **Developed by:** openclimatefix +- **Model type:** Fusion model +- **Language(s) (NLP):** en +- **License:** mit + + +# Training Details + +## Data + + + +The model is trained on data from 2019-2022 and validated on data from 2022-2023. See experimental notes [here](https://github.com/openclimatefix/PVNet/tree/main/experiments/india) + + +### Preprocessing + +Data is prepared with the `ocf_datapipes.training.pvnet_site` datapipe [2]. + + +## Results + +The training logs for the current model can be found here: +{{ wandb_links }} + + +### Hardware + +Trained on a single NVIDIA Tesla T4 + +### Software + +- [1] https://github.com/openclimatefix/PVNet +- [2] https://github.com/openclimatefix/ocf_datapipes diff --git a/pvnet/models/model_card_template.md b/pvnet/models/model_cards/pv_uk_regional_model_card_template.md similarity index 77% rename from pvnet/models/model_card_template.md rename to pvnet/models/model_cards/pv_uk_regional_model_card_template.md index 8ae10af6..0008406c 100644 --- a/pvnet/models/model_card_template.md +++ b/pvnet/models/model_cards/pv_uk_regional_model_card_template.md @@ -12,7 +12,7 @@ ## Model Description -This model class uses satellite data, numericl weather predictions, and recent Grid Service Point( GSP) PV power output to forecast the near-term (~8 hours) PV power output at all GSPs. More information can be found in the model repo [1] and experimental notes in [this google doc](https://docs.google.com/document/d/1fbkfkBzp16WbnCg7RDuRDvgzInA6XQu3xh4NCjV-WDA/edit?usp=sharing). +This model class uses satellite data, numerical weather predictions, and recent Grid Service Point( GSP) PV power output to forecast the near-term (~8 hours) PV power output at all GSPs. More information can be found in the model repo [1] and experimental notes in [this google doc](https://docs.google.com/document/d/1fbkfkBzp16WbnCg7RDuRDvgzInA6XQu3xh4NCjV-WDA/edit?usp=sharing). - **Developed by:** openclimatefix - **Model type:** Fusion model diff --git a/pvnet/models/model_cards/wind_india_model_card_template.md b/pvnet/models/model_cards/wind_india_model_card_template.md new file mode 100644 index 00000000..39f84d6b --- /dev/null +++ b/pvnet/models/model_cards/wind_india_model_card_template.md @@ -0,0 +1,51 @@ +--- +{{ card_data }} +--- + + + + + + +# WindNet + +## Model Description + + +This model class uses numerical weather predictions from providers such as ECMWF to forecast the wind power in North West India over the next 48 hours at 15 minute granularity. More information can be found in the model repo [1] and experimental notes [here](https://github.com/openclimatefix/PVNet/tree/main/experiments/india). + + +- **Developed by:** openclimatefix +- **Model type:** Fusion model +- **Language(s) (NLP):** en +- **License:** mit + + +# Training Details + +## Data + + + +The model is trained on data from 2019-2022 and validated on data from 2022-2023. See experimental notes [here](https://github.com/openclimatefix/PVNet/tree/main/experiments/india) + + +### Preprocessing + +Data is prepared with the `ocf_datapipes.training.windnet` datapipe [2]. + + +## Results + +The training logs for the current model can be found here: +{{ wandb_links }} + + +### Hardware + +Trained on a single NVIDIA Tesla T4 + +### Software + +- [1] https://github.com/openclimatefix/PVNet +- [2] https://github.com/openclimatefix/ocf_datapipes diff --git a/scripts/checkpoint_to_huggingface.py b/scripts/checkpoint_to_huggingface.py index ee876a5f..0005b396 100644 --- a/scripts/checkpoint_to_huggingface.py +++ b/scripts/checkpoint_to_huggingface.py @@ -2,33 +2,35 @@ use: python checkpoint_to_huggingface.py "path/to/model/checkpoints" \ + --huggingface_repo="openclimatefix/pvnet_uk_region" \ + --wandb_repo="openclimatefix/pvnet2.1"" \ --local-path="~/tmp/this_model" \ --no-push-to-hub """ import tempfile -from typing import Optional import typer import wandb from pvnet.load_model import get_model_from_checkpoints -wandb_repo = "openclimatefix/pvnet2.1" -huggingface_repo = "openclimatefix/pvnet_uk_region" - def push_to_huggingface( checkpoint_dir_paths: list[str], + huggingface_repo: str = "openclimatefix/pvnet_uk_region", # e.g. openclimatefix/windnet_india + wandb_repo: str | None = "openclimatefix/pvnet2.1", val_best: bool = True, - wandb_ids: Optional[list[str]] = None, - local_path: Optional[str] = None, + wandb_ids: list[str] | None = [], + local_path: str | None = None, push_to_hub: bool = True, ): - """Push a local model to pvnet_v2 huggingface model repo + """Push a local model to a huggingface model repo Args: checkpoint_dir_paths: Path(s) of the checkpoint directory(ies) + huggingface_repo: Name of the HuggingFace repo to push the model to + wandb_repo: Name of the wandb repo which has training logs val_best: Use best model according to val loss, else last saved model wandb_ids: The wandb ID code(s) local_path: Where to save the local copy of the model @@ -65,6 +67,7 @@ def push_to_huggingface( model_output_dir, config=model_config, data_config=data_config, + wandb_repo=wandb_repo, wandb_ids=wandb_ids, push_to_hub=push_to_hub, repo_id=huggingface_repo if push_to_hub else None,