Skip to content

Commit

Permalink
Merge branch 'main' into add_flare_client_context
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiyueXu77 authored Jan 23, 2025
2 parents adf3c12 + 67cbdf8 commit 0ece3c2
Show file tree
Hide file tree
Showing 168 changed files with 3,827 additions and 1,622 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ include versioneer.py
include nvflare/_version.py
include nvflare/libs/*.so
include nvflare/fuel/utils/*.json
include nvflare/private/fed/app/simulator/log_config.json
4 changes: 2 additions & 2 deletions docs/resources/log_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"()": "nvflare.fuel.utils.log_utils.BaseFormatter",
"fmt": "%(asctime)s - %(name)s - %(levelname)s - %(fl_ctx)s - %(message)s"
},
"colorFormatter": {
"consoleFormatter": {
"()": "nvflare.fuel.utils.log_utils.ColorFormatter",
"fmt": "%(asctime)s - %(name)s - %(levelname)s - %(fl_ctx)s - %(message)s"
},
Expand All @@ -25,7 +25,7 @@
"consoleHandler": {
"class": "logging.StreamHandler",
"level": "DEBUG",
"formatter": "colorFormatter",
"formatter": "consoleFormatter",
"filters": [],
"stream": "ext://sys.stdout"
},
Expand Down
8 changes: 4 additions & 4 deletions docs/user_guide/configurations/logging_configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ See the `configuration dictionary schema <(https://docs.python.org/3/library/log
"()": "nvflare.fuel.utils.log_utils.BaseFormatter",
"fmt": "%(asctime)s - %(name)s - %(levelname)s - %(fl_ctx)s - %(message)s"
},
"colorFormatter": {
"consoleFormatter": {
"()": "nvflare.fuel.utils.log_utils.ColorFormatter",
"fmt": "%(asctime)s - %(name)s - %(levelname)s - %(fl_ctx)s - %(message)s"
},
Expand All @@ -52,7 +52,7 @@ See the `configuration dictionary schema <(https://docs.python.org/3/library/log
"consoleHandler": {
"class": "logging.StreamHandler",
"level": "DEBUG",
"formatter": "colorFormatter",
"formatter": "consoleFormatter",
"filters": [],
"stream": "ext://sys.stdout"
},
Expand Down Expand Up @@ -147,7 +147,7 @@ Example configuration:

.. code-block:: json
"colorFormatter": {
"consoleFormatter": {
"()": "nvflare.fuel.utils.log_utils.ColorFormatter",
"fmt": "%(asctime)s - %(name)s - %(levelname)s - %(fl_ctx)s - %(message)s",
"level_colors": {
Expand Down Expand Up @@ -221,7 +221,7 @@ Example configuration:
"consoleHandler": {
"class": "logging.StreamHandler",
"level": "DEBUG",
"formatter": "colorFormatter",
"formatter": "consoleFormatter",
"filters": ["FLFilter"],
"stream": "ext://sys.stdout"
}
Expand Down
4 changes: 2 additions & 2 deletions examples/advanced/brats18/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ First, we add the image and datalist directory roots to `config_train.json` file
```
for alg in brats_central brats_fedavg brats_fedavg_dp
do
sed -i "s|DATASET_ROOT|${PWD}/dataset_brats18/dataset|g" configs/${alg}/config/config_train.json
sed -i "s|DATALIST_ROOT|${PWD}/dataset_brats18/datalist|g" configs/${alg}/config/config_train.json
sed -i "s|DATASET_ROOT|${PWD}/dataset_brats18/dataset|g" configs/${alg}/app/config/config_train.json
sed -i "s|DATALIST_ROOT|${PWD}/dataset_brats18/datalist|g" configs/${alg}/app/config/config_train.json
done
```

Expand Down
10 changes: 5 additions & 5 deletions examples/advanced/llm_hf/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
nvflare
torch
torch==2.5.1
datasets
tensorboard
transformers
peft
trl
bitsandbytes
transformers==4.48.0
peft==0.14.0
trl==0.13.0
bitsandbytes
9 changes: 1 addition & 8 deletions examples/advanced/llm_hf/src/hf_sft_peft_fl.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import numpy as np
import torch
from peft import LoraConfig, get_peft_model, get_peft_model_state_dict, set_peft_model_state_dict, utils
from transformers import AutoModelForCausalLM, AutoTokenizer, trainer_utils
from transformers import AutoModelForCausalLM, trainer_utils
from trl import SFTConfig, SFTTrainer

import nvflare.client as flare
Expand Down Expand Up @@ -126,11 +126,6 @@ def main():
model = get_peft_model(model, peft_config)
model.config.pretraining_tp = 1

# Set tokenizer
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
tokenizer.pad_token = tokenizer.eos_token
tokenizer.padding_side = "right"

# Training arguments
train_args = SFTConfig(
output_dir=args.output_path,
Expand Down Expand Up @@ -159,8 +154,6 @@ def main():
train_dataset=dataset_train,
eval_dataset=dataset_valid,
peft_config=peft_config,
tokenizer=tokenizer,
packing=False,
formatting_func=format_instruction,
args=train_args,
)
Expand Down
9 changes: 1 addition & 8 deletions examples/advanced/llm_hf/utils/hf_sft_peft.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import numpy as np
import torch
from peft import LoraConfig, get_peft_model
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers import AutoModelForCausalLM
from trl import SFTConfig, SFTTrainer

torch.manual_seed(0)
Expand Down Expand Up @@ -114,11 +114,6 @@ def main():
model = get_peft_model(model, peft_config)
model.config.pretraining_tp = 1

# Set tokenizer
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
tokenizer.pad_token = tokenizer.eos_token
tokenizer.padding_side = "right"

# Training arguments
train_args = SFTConfig(
output_dir=args.output_path,
Expand All @@ -144,8 +139,6 @@ def main():
train_dataset=dataset_train,
eval_dataset=dataset_valid,
peft_config=peft_config,
tokenizer=tokenizer,
packing=False,
formatting_func=format_instruction,
args=train_args,
)
Expand Down
9 changes: 1 addition & 8 deletions examples/advanced/llm_hf/utils/hf_sft_peft_iter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import numpy as np
import torch
from peft import LoraConfig, get_peft_model, get_peft_model_state_dict, set_peft_model_state_dict, utils
from transformers import AutoModelForCausalLM, AutoTokenizer, trainer_utils
from transformers import AutoModelForCausalLM, trainer_utils
from trl import SFTConfig, SFTTrainer

torch.manual_seed(0)
Expand Down Expand Up @@ -115,11 +115,6 @@ def main():
model = get_peft_model(model, peft_config)
model.config.pretraining_tp = 1

# Set tokenizer
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
tokenizer.pad_token = tokenizer.eos_token
tokenizer.padding_side = "right"

# Training arguments
train_args = SFTConfig(
output_dir=args.output_path,
Expand Down Expand Up @@ -147,8 +142,6 @@ def main():
train_dataset=dataset_train,
eval_dataset=dataset_valid,
peft_config=peft_config,
tokenizer=tokenizer,
packing=False,
formatting_func=format_instruction,
args=train_args,
)
Expand Down
84 changes: 84 additions & 0 deletions examples/tutorials/custom_log_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"version": 1,
"disable_existing_loggers": false,
"formatters": {
"baseFormatter": {
"()": "nvflare.fuel.utils.log_utils.BaseFormatter",
"fmt": "%(asctime)s - %(name)s - %(levelname)s - %(fl_ctx)s - %(message)s"
},
"consoleFormatter": {
"()": "nvflare.fuel.utils.log_utils.ColorFormatter",
"fmt": "%(asctime)s - %(identity)s - %(name)s - %(levelname)s - %(message)s",
"datefmt": "%Y-%m-%d %H:%M:%S",
"logger_colors": {
"NPModelPersistor": "blue"
}
},
"jsonFormatter": {
"()": "nvflare.fuel.utils.log_utils.JsonFormatter",
"fmt": "%(asctime)s - %(name)s - %(fullName)s - %(levelname)s - %(fl_ctx)s - %(message)s"
}
},
"filters": {
"FLFilter": {
"()": "nvflare.fuel.utils.log_utils.LoggerNameFilter",
"logger_names": ["custom", "nvflare.app_common", "nvflare.app_opt"]
}
},
"handlers": {
"consoleHandler": {
"class": "logging.StreamHandler",
"level": "DEBUG",
"formatter": "consoleFormatter",
"filters": ["FLFilter"],
"stream": "ext://sys.stdout"
},
"logFileHandler": {
"class": "logging.handlers.RotatingFileHandler",
"level": "DEBUG",
"formatter": "baseFormatter",
"filename": "log.txt",
"mode": "a",
"maxBytes": 20971520,
"backupCount": 10
},
"errorFileHandler": {
"class": "logging.handlers.RotatingFileHandler",
"level": "ERROR",
"formatter": "baseFormatter",
"filename": "log_error.txt",
"mode": "a",
"maxBytes": 20971520,
"backupCount": 10
},
"jsonFileHandler": {
"class": "logging.handlers.RotatingFileHandler",
"level": "DEBUG",
"formatter": "jsonFormatter",
"filename": "log.json",
"mode": "a",
"maxBytes": 20971520,
"backupCount": 10
},
"FLFileHandler": {
"class": "logging.handlers.RotatingFileHandler",
"level": "DEBUG",
"formatter": "baseFormatter",
"filters": ["FLFilter"],
"filename": "log_fl.txt",
"mode": "a",
"maxBytes": 20971520,
"backupCount": 10,
"delay": true
}
},
"loggers": {
"root": {
"level": "INFO",
"handlers": ["consoleHandler", "logFileHandler", "errorFileHandler", "jsonFileHandler", "FLFileHandler"]
},
"nvflare.app_common.aggregators": {
"level": "DEBUG"
}
}
}
Loading

0 comments on commit 0ece3c2

Please sign in to comment.