From 1a5cfdc7cb7f9b5269b8c62b7a92f5f30e5f110f Mon Sep 17 00:00:00 2001 From: Sukhil Patel Date: Wed, 24 Jul 2024 16:48:57 +0100 Subject: [PATCH 1/7] Update default for wandb_ids --- scripts/checkpoint_to_huggingface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/checkpoint_to_huggingface.py b/scripts/checkpoint_to_huggingface.py index ee876a5f..d1d7deab 100644 --- a/scripts/checkpoint_to_huggingface.py +++ b/scripts/checkpoint_to_huggingface.py @@ -21,7 +21,7 @@ def push_to_huggingface( checkpoint_dir_paths: list[str], val_best: bool = True, - wandb_ids: Optional[list[str]] = None, + wandb_ids: list[str] = [], local_path: Optional[str] = None, push_to_hub: bool = True, ): From e2b27acb311d5c0adf6d65a3f7f8063bb4e40f5a Mon Sep 17 00:00:00 2001 From: Sukhil Patel Date: Tue, 6 Aug 2024 09:45:35 +0100 Subject: [PATCH 2/7] Update type hints --- scripts/checkpoint_to_huggingface.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/checkpoint_to_huggingface.py b/scripts/checkpoint_to_huggingface.py index d1d7deab..e0ea9b23 100644 --- a/scripts/checkpoint_to_huggingface.py +++ b/scripts/checkpoint_to_huggingface.py @@ -7,7 +7,6 @@ """ import tempfile -from typing import Optional import typer import wandb @@ -21,8 +20,8 @@ def push_to_huggingface( checkpoint_dir_paths: list[str], val_best: bool = True, - wandb_ids: list[str] = [], - 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 From 91e26ad3eb4e669d28af780ffa986cc30d6637c1 Mon Sep 17 00:00:00 2001 From: Sukhil Patel Date: Wed, 7 Aug 2024 11:42:54 +0100 Subject: [PATCH 3/7] Fix model cards --- pvnet/models/base_model.py | 21 ++++++-- .../{ => model_cards}/model_card_template.md | 2 +- .../pvnet_india_model_card_template.md | 51 +++++++++++++++++++ .../windnet_model_card_template.md | 51 +++++++++++++++++++ scripts/checkpoint_to_huggingface.py | 13 +++-- 5 files changed, 129 insertions(+), 9 deletions(-) rename pvnet/models/{ => model_cards}/model_card_template.md (77%) create mode 100644 pvnet/models/model_cards/pvnet_india_model_card_template.md create mode 100644 pvnet/models/model_cards/windnet_model_card_template.md diff --git a/pvnet/models/base_model.py b/pvnet/models/base_model.py index b4a23d3d..53da9621 100644 --- a/pvnet/models/base_model.py +++ b/pvnet/models/base_model.py @@ -230,6 +230,8 @@ def save_pretrained( data_config: Optional[Union[str, Path]], repo_id: Optional[str] = None, push_to_hub: bool = False, + huggingface_repo: Optional[str] = None, + wandb_repo: Optional[str] = None, wandb_ids: Optional[Union[list[str], str]] = None, card_template_path=None, **kwargs, @@ -248,9 +250,11 @@ 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. + huggingface_repo: Identifier of the repo on HuggingFace. + 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 +281,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 = huggingface_repo.split('/')[1] + if model_name == "windnet_india": + model_card = "windnet_model_card_template.md" + elif model_name == "pvnet_india": + model_card = "pvnet_india_model_card_template.md" + else: + model_card = "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 +302,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_card_template.md b/pvnet/models/model_cards/model_card_template.md similarity index 77% rename from pvnet/models/model_card_template.md rename to pvnet/models/model_cards/model_card_template.md index 8ae10af6..0008406c 100644 --- a/pvnet/models/model_card_template.md +++ b/pvnet/models/model_cards/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/pvnet_india_model_card_template.md b/pvnet/models/model_cards/pvnet_india_model_card_template.md new file mode 100644 index 00000000..576538ec --- /dev/null +++ b/pvnet/models/model_cards/pvnet_india_model_card_template.md @@ -0,0 +1,51 @@ +--- +{{ card_data }} +--- + + + + + + +# PVNet India + +## Model Description + + +This model class uses numerical weather prediction and recent wind power output 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_cards/windnet_model_card_template.md b/pvnet/models/model_cards/windnet_model_card_template.md new file mode 100644 index 00000000..8a8dfd85 --- /dev/null +++ b/pvnet/models/model_cards/windnet_model_card_template.md @@ -0,0 +1,51 @@ +--- +{{ card_data }} +--- + + + + + + +# WindNet + +## Model Description + + +This model class uses numerical weather prediction and recent wind power output 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 e0ea9b23..9fa36a9c 100644 --- a/scripts/checkpoint_to_huggingface.py +++ b/scripts/checkpoint_to_huggingface.py @@ -2,6 +2,8 @@ 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 """ @@ -13,21 +15,22 @@ 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", # or e.g. openclimatefix/windnet_india + wandb_repo: str | None = "openclimatefix/pvnet2.1", val_best: bool = True, 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 @@ -64,6 +67,8 @@ def push_to_huggingface( model_output_dir, config=model_config, data_config=data_config, + huggingface_repo=huggingface_repo, + wandb_repo=wandb_repo, wandb_ids=wandb_ids, push_to_hub=push_to_hub, repo_id=huggingface_repo if push_to_hub else None, From 8c00aab482894d68ad1fa42f2fb5b7b7827a6989 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 7 Aug 2024 10:43:09 +0000 Subject: [PATCH 4/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pvnet/models/base_model.py | 6 +++--- pvnet/models/model_cards/pvnet_india_model_card_template.md | 2 +- pvnet/models/model_cards/windnet_model_card_template.md | 2 +- scripts/checkpoint_to_huggingface.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pvnet/models/base_model.py b/pvnet/models/base_model.py index 53da9621..c9849ef9 100644 --- a/pvnet/models/base_model.py +++ b/pvnet/models/base_model.py @@ -282,10 +282,10 @@ def save_pretrained( minimize_data_config(new_data_config_path, new_data_config_path, self) # Get appropriate model card - model_name = huggingface_repo.split('/')[1] - if model_name == "windnet_india": + model_name = huggingface_repo.split("/")[1] + if model_name == "windnet_india": model_card = "windnet_model_card_template.md" - elif model_name == "pvnet_india": + elif model_name == "pvnet_india": model_card = "pvnet_india_model_card_template.md" else: model_card = "model_card_template.md" diff --git a/pvnet/models/model_cards/pvnet_india_model_card_template.md b/pvnet/models/model_cards/pvnet_india_model_card_template.md index 576538ec..36079953 100644 --- a/pvnet/models/model_cards/pvnet_india_model_card_template.md +++ b/pvnet/models/model_cards/pvnet_india_model_card_template.md @@ -12,7 +12,7 @@ ## Model Description -This model class uses numerical weather prediction and recent wind power output 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). +This model class uses numerical weather prediction and recent wind power output 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 diff --git a/pvnet/models/model_cards/windnet_model_card_template.md b/pvnet/models/model_cards/windnet_model_card_template.md index 8a8dfd85..189193e9 100644 --- a/pvnet/models/model_cards/windnet_model_card_template.md +++ b/pvnet/models/model_cards/windnet_model_card_template.md @@ -12,7 +12,7 @@ ## Model Description -This model class uses numerical weather prediction and recent wind power output 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). +This model class uses numerical weather prediction and recent wind power output 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 diff --git a/scripts/checkpoint_to_huggingface.py b/scripts/checkpoint_to_huggingface.py index 9fa36a9c..31903f90 100644 --- a/scripts/checkpoint_to_huggingface.py +++ b/scripts/checkpoint_to_huggingface.py @@ -18,7 +18,7 @@ def push_to_huggingface( checkpoint_dir_paths: list[str], - huggingface_repo: str = "openclimatefix/pvnet_uk_region", # or e.g. openclimatefix/windnet_india + huggingface_repo: str = "openclimatefix/pvnet_uk_region", # or e.g. openclimatefix/windnet_india wandb_repo: str | None = "openclimatefix/pvnet2.1", val_best: bool = True, wandb_ids: list[str] | None = [], From cc9cc41d3671f0e92d89e09a9e7b7f91abe30f67 Mon Sep 17 00:00:00 2001 From: Sukhil Patel Date: Wed, 7 Aug 2024 12:33:24 +0100 Subject: [PATCH 5/7] linting --- scripts/checkpoint_to_huggingface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/checkpoint_to_huggingface.py b/scripts/checkpoint_to_huggingface.py index 31903f90..69b8ba32 100644 --- a/scripts/checkpoint_to_huggingface.py +++ b/scripts/checkpoint_to_huggingface.py @@ -18,7 +18,7 @@ def push_to_huggingface( checkpoint_dir_paths: list[str], - huggingface_repo: str = "openclimatefix/pvnet_uk_region", # or e.g. openclimatefix/windnet_india + 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: list[str] | None = [], From 8742ebc8a6ce4ce1683aadc0c1aad8407edbe162 Mon Sep 17 00:00:00 2001 From: Sukhil Patel Date: Wed, 7 Aug 2024 15:00:21 +0100 Subject: [PATCH 6/7] Correct model cards --- pvnet/models/base_model.py | 6 +++--- ...del_card_template.md => pv_india_model_card_template.md} | 2 +- ...rd_template.md => pv_uk_regional_model_card_template.md} | 0 ...l_card_template.md => wind_india_model_card_template.md} | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) rename pvnet/models/model_cards/{pvnet_india_model_card_template.md => pv_india_model_card_template.md} (77%) rename pvnet/models/model_cards/{model_card_template.md => pv_uk_regional_model_card_template.md} (100%) rename pvnet/models/model_cards/{windnet_model_card_template.md => wind_india_model_card_template.md} (75%) diff --git a/pvnet/models/base_model.py b/pvnet/models/base_model.py index c9849ef9..7a275262 100644 --- a/pvnet/models/base_model.py +++ b/pvnet/models/base_model.py @@ -284,11 +284,11 @@ def save_pretrained( # Get appropriate model card model_name = huggingface_repo.split("/")[1] if model_name == "windnet_india": - model_card = "windnet_model_card_template.md" + model_card = "wind_india_model_card_template.md" elif model_name == "pvnet_india": - model_card = "pvnet_india_model_card_template.md" + model_card = "pv_india_model_card_template.md" else: - model_card = "model_card_template.md" + model_card = "pv_uk_regional_model_card_template.md" # Creating and saving model card. card_data = ModelCardData(language="en", license="mit", library_name="pytorch") diff --git a/pvnet/models/model_cards/pvnet_india_model_card_template.md b/pvnet/models/model_cards/pv_india_model_card_template.md similarity index 77% rename from pvnet/models/model_cards/pvnet_india_model_card_template.md rename to pvnet/models/model_cards/pv_india_model_card_template.md index 36079953..4f16a3e8 100644 --- a/pvnet/models/model_cards/pvnet_india_model_card_template.md +++ b/pvnet/models/model_cards/pv_india_model_card_template.md @@ -12,7 +12,7 @@ ## Model Description -This model class uses numerical weather prediction and recent wind power output 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). +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 diff --git a/pvnet/models/model_cards/model_card_template.md b/pvnet/models/model_cards/pv_uk_regional_model_card_template.md similarity index 100% rename from pvnet/models/model_cards/model_card_template.md rename to pvnet/models/model_cards/pv_uk_regional_model_card_template.md diff --git a/pvnet/models/model_cards/windnet_model_card_template.md b/pvnet/models/model_cards/wind_india_model_card_template.md similarity index 75% rename from pvnet/models/model_cards/windnet_model_card_template.md rename to pvnet/models/model_cards/wind_india_model_card_template.md index 189193e9..39f84d6b 100644 --- a/pvnet/models/model_cards/windnet_model_card_template.md +++ b/pvnet/models/model_cards/wind_india_model_card_template.md @@ -12,7 +12,7 @@ ## Model Description -This model class uses numerical weather prediction and recent wind power output 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). +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 From 5e07cc15fe33b0d387f4b797cd8458152d794f30 Mon Sep 17 00:00:00 2001 From: Sukhil Patel Date: Wed, 7 Aug 2024 15:29:10 +0100 Subject: [PATCH 7/7] Remove duplicated parameter --- pvnet/models/base_model.py | 4 +--- scripts/checkpoint_to_huggingface.py | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/pvnet/models/base_model.py b/pvnet/models/base_model.py index 7a275262..eab47ccf 100644 --- a/pvnet/models/base_model.py +++ b/pvnet/models/base_model.py @@ -230,7 +230,6 @@ def save_pretrained( data_config: Optional[Union[str, Path]], repo_id: Optional[str] = None, push_to_hub: bool = False, - huggingface_repo: Optional[str] = None, wandb_repo: Optional[str] = None, wandb_ids: Optional[Union[list[str], str]] = None, card_template_path=None, @@ -251,7 +250,6 @@ def save_pretrained( 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. - huggingface_repo: Identifier of the repo on HuggingFace. 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 @@ -282,7 +280,7 @@ def save_pretrained( minimize_data_config(new_data_config_path, new_data_config_path, self) # Get appropriate model card - model_name = huggingface_repo.split("/")[1] + model_name = repo_id.split("/")[1] if model_name == "windnet_india": model_card = "wind_india_model_card_template.md" elif model_name == "pvnet_india": diff --git a/scripts/checkpoint_to_huggingface.py b/scripts/checkpoint_to_huggingface.py index 69b8ba32..0005b396 100644 --- a/scripts/checkpoint_to_huggingface.py +++ b/scripts/checkpoint_to_huggingface.py @@ -67,7 +67,6 @@ def push_to_huggingface( model_output_dir, config=model_config, data_config=data_config, - huggingface_repo=huggingface_repo, wandb_repo=wandb_repo, wandb_ids=wandb_ids, push_to_hub=push_to_hub,