Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub Action for Nightly #1309

Merged
merged 5 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Tests
on:
push:
pull_request:
workflow_call:
release:
types: [created]
jobs:
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Nightly

on:
workflow_dispatch: # To Generate wheels on demand outside of schedule.
schedule:
- cron: '0 3 * * *' # run at 3 AM UTC / 8 PM PDT

permissions:
contents: read

jobs:
run-test-for-nightly:
uses: ./.github/workflows/actions.yml
nightly:
name: Build Wheel file and upload
needs: [run-test-for-nightly]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Get pip cache dir
id: pip-cache
run: |
python -m pip install --upgrade pip setuptools
echo "::set-output name=dir::$(pip cache dir)"
- name: pip cache
uses: actions/cache@v2
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools
pip install twine
pip install -r requirements.txt --progress-bar off
- name: Build wheel file
run: |
python pip_build.py --nightly
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_NIGHTLY_API_TOKEN }}
packages-dir: dist/
verbose: true
2 changes: 1 addition & 1 deletion keras_nlp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
from keras_nlp import utils

# This is the global source of truth for the version number.
__version__ = "0.7.0.dev0"
__version__ = "0.7.0"
41 changes: 34 additions & 7 deletions pip_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
```
"""
import argparse
import datetime
import glob
import os
import pathlib
Expand All @@ -45,14 +46,37 @@
]


def build():
def export_version_string(version, is_nightly=False):
"""Export Version and Package Name."""
if is_nightly:
date = datetime.datetime.now()
version += f".dev{date.strftime('%Y%m%d%H')}"
# Replaces `name="keras"` string in `setup.py` with `keras-nightly`
with open("setup.py") as f:
setup_contents = f.read()
with open("setup.py", "w") as f:
setup_contents = setup_contents.replace(
'name="keras-nlp"', 'name="keras-nlp-nightly"'
)
setup_contents = setup_contents.replace(
'"tensorflow-text', '"tf-nightly", "tensorflow-text-nightly'
)
f.write(setup_contents)

# Make sure to export the __version__ string
with open(os.path.join(package, "__init__.py")) as f:
init_contents = f.read()
with open(os.path.join(package, "__init__.py"), "w") as f:
f.write(init_contents + "\n\n" + f'__version__ = "{version}"\n')


def build(root_path, is_nightly=False):
if os.path.exists(build_directory):
raise ValueError(f"Directory already exists: {build_directory}")

whl_path = None
try:
# Copy sources (`keras_nlp/` directory and setup files) to build directory
root_path = pathlib.Path(__file__).parent.resolve()
os.chdir(root_path)
os.mkdir(build_directory)
shutil.copytree(package, os.path.join(build_directory, package))
Expand All @@ -69,10 +93,7 @@ def build():
# Make sure to export the __version__ string
from keras_nlp.src import __version__ # noqa: E402

with open(os.path.join(package, "__init__.py")) as f:
init_contents = f.read()
with open(os.path.join(package, "__init__.py"), "w") as f:
f.write(init_contents + "\n\n" + f'__version__ = "{__version__}"\n')
export_version_string(__version__, is_nightly)

# Build the package
os.system("python3 -m build")
Expand Down Expand Up @@ -109,7 +130,13 @@ def install_whl(whl_fpath):
action="store_true",
help="Whether to install the generated wheel file.",
)
parser.add_argument(
"--nightly",
action="store_true",
help="Whether to generate nightly wheel file.",
)
args = parser.parse_args()
whl_path = build()
root_path = pathlib.Path(__file__).parent.resolve()
whl_path = build(root_path, args.nightly)
if whl_path and args.install:
install_whl(whl_path)
4 changes: 2 additions & 2 deletions requirements-jax-cuda.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Tensorflow cpu-only version.
tf-nightly-cpu==2.16.0.dev20231103 # Pin a working nightly until rc0.
tensorflow-text-nightly==2.16.0.dev20231103 # Pin a working nightly until rc0.
tf-nightly-cpu==2.16.0.dev20231104 # Pin a working nightly until rc0.
tensorflow-text-nightly==2.16.0.dev20231104 # Pin a working nightly until rc0.

# Torch cpu-only version.
--extra-index-url https://download.pytorch.org/whl/cpu
Expand Down
4 changes: 2 additions & 2 deletions requirements-tensorflow-cuda.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Tensorflow with cuda support.
--extra-index-url https://pypi.nvidia.com
tf-nightly[and-cuda]==2.16.0.dev20231103 # Pin a working nightly until rc0.
tensorflow-text-nightly==2.16.0.dev20231103 # Pin a working nightly until rc0.
tf-nightly[and-cuda]==2.16.0.dev20231104 # Pin a working nightly until rc0.
tensorflow-text-nightly==2.16.0.dev20231104 # Pin a working nightly until rc0.

# Torch cpu-only version.
--extra-index-url https://download.pytorch.org/whl/cpu
Expand Down
4 changes: 2 additions & 2 deletions requirements-torch-cuda.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Tensorflow cpu-only version.
tf-nightly-cpu==2.16.0.dev20231103 # Pin a working nightly until rc0.
tensorflow-text-nightly==2.16.0.dev20231103 # Pin a working nightly until rc0.
tf-nightly-cpu==2.16.0.dev20231104 # Pin a working nightly until rc0.
tensorflow-text-nightly==2.16.0.dev20231104 # Pin a working nightly until rc0.

# Torch with cuda support.
--extra-index-url https://download.pytorch.org/whl/cu118
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Tensorflow.
tf-nightly-cpu==2.16.0.dev20231103 # Pin a working nightly until rc0.
tensorflow-text-nightly==2.16.0.dev20231103 # Pin a working nightly until rc0.
tf-nightly-cpu==2.16.0.dev20231104 # Pin a working nightly until rc0.
tensorflow-text-nightly==2.16.0.dev20231104 # Pin a working nightly until rc0.

# Torch.
--extra-index-url https://download.pytorch.org/whl/cpu
Expand Down