From aae47ab59aabfdc29fe8e312aa2a11ed8e784633 Mon Sep 17 00:00:00 2001 From: Oleg S <97077423+RobotSail@users.noreply.github.com> Date: Tue, 15 Oct 2024 23:28:29 -0400 Subject: [PATCH 1/3] create script to output loss curve Signed-off-by: Oleg S <97077423+RobotSail@users.noreply.github.com> --- scripts/create-loss-graph.py | 52 ++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 scripts/create-loss-graph.py diff --git a/scripts/create-loss-graph.py b/scripts/create-loss-graph.py new file mode 100644 index 00000000..f4cc6b1e --- /dev/null +++ b/scripts/create-loss-graph.py @@ -0,0 +1,52 @@ +# SPDX-License-Identifier: Apache-2.0 +# Standard +from argparse import ArgumentParser, Namespace +from base64 import b64encode +from io import BytesIO +from pathlib import Path +import json + +# Third Party +from matplotlib import pyplot as plt + + +def main(args: Namespace): + log_file = Path(args.log_file) + if not log_file.exists(): + raise FileNotFoundError(f'log file "{args.log_file}" does not exist') + + if not log_file.is_file(): + raise RuntimeError(f'log file cannot be a directory: "{log_file}"') + + with open(Path(log_file), "r", encoding="utf-8") as infile: + contents = [json.loads(l) for l in infile.read().splitlines()] + + loss_data = [item["total_loss"] for item in contents if "total_loss" in item] + + # create the plot + plt.figure() + plt.plot(loss_data) + plt.xlabel("Steps") + plt.ylabel("Loss") + plt.title("Training performance over fixed dataset") + + buf = BytesIO() + plt.savefig(buf, format="png") + buf.seek(0) + + imgb64 = b64encode(buf.read()).decode("utf-8") + + output_file = Path(args.output_file) if args.output_file else None + if output_file: + output_file.write_text(imgb64, encoding="utf-8") + else: + # just print the file without including a newline, this way it can be piped + print(imgb64, end="") + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("--log-file", type=str) + parser.add_argument("--output-file", type=str, default=None) + args = parser.parse_args() + main(args) From ef34b4a995dac48eec48b88139c0871a78bad04d Mon Sep 17 00:00:00 2001 From: Oleg S <97077423+RobotSail@users.noreply.github.com> Date: Tue, 15 Oct 2024 23:37:13 -0400 Subject: [PATCH 2/3] add action for printing out the loss Signed-off-by: Oleg S <97077423+RobotSail@users.noreply.github.com> --- .github/workflows/print-loss.yml | 43 ++++++++++++++++++++++++++++++++ requirements-dev.txt | 4 +++ 2 files changed, 47 insertions(+) create mode 100644 .github/workflows/print-loss.yml diff --git a/.github/workflows/print-loss.yml b/.github/workflows/print-loss.yml new file mode 100644 index 00000000..bfe51b06 --- /dev/null +++ b/.github/workflows/print-loss.yml @@ -0,0 +1,43 @@ +name: Print Loss + +on: + pull_request: + types: [opened, reopened] + branches: + - main + +jobs: + print-loss: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements-dev.txt + + - name: Generate test data + run: | + printf '{"total_loss": 2.0}\n{"total_loss": 1.8023}\n{"total_loss": 1.52324}\n{"total_loss": 1.3234}' > test-log.jsonl + ls -al + - name: Print loss + run: | + python scripts/create-loss-graph.py --log-file test-log.jsonl + - name: Print a comment + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: 'Thank you for your contribution! Please make sure to review our contribution guidelines.' + }) \ No newline at end of file diff --git a/requirements-dev.txt b/requirements-dev.txt index a0dff1ed..26c9141a 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -11,3 +11,7 @@ ipython ipykernel jupyter + +# for printing out the loss +matplotlib +numpy From 9956e21fa45cb4d6e60960b072b28c3fbbbd14a9 Mon Sep 17 00:00:00 2001 From: Oleg S <97077423+RobotSail@users.noreply.github.com> Date: Tue, 15 Oct 2024 23:40:40 -0400 Subject: [PATCH 3/3] update action --- .github/workflows/print-loss.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/print-loss.yml b/.github/workflows/print-loss.yml index bfe51b06..55737432 100644 --- a/.github/workflows/print-loss.yml +++ b/.github/workflows/print-loss.yml @@ -12,10 +12,10 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: '3.x' @@ -32,6 +32,7 @@ jobs: run: | python scripts/create-loss-graph.py --log-file test-log.jsonl - name: Print a comment + uses: actions/github-script@v7 with: github-token: ${{secrets.GITHUB_TOKEN}} script: |