Skip to content

Commit db574ce

Browse files
committed
ci: run inference with java
Use downloaded model artifact and run Main.java with Gradle for inference
1 parent 3ee90d3 commit db574ce

File tree

1 file changed

+109
-99
lines changed

1 file changed

+109
-99
lines changed

.github/workflows/java-app.yml

Lines changed: 109 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,109 @@
1-
# This workflow converts a Hugging Face model to ONNX format, builds a Java application with Gradle,
2-
# and generates and submits a dependency graph for the project.
3-
name: Java application
4-
5-
on:
6-
push:
7-
branches: ["main"]
8-
pull_request:
9-
branches: ["main"]
10-
11-
permissions:
12-
contents: read
13-
14-
jobs:
15-
convert-model-to-onnx:
16-
runs-on: ubuntu-latest
17-
18-
steps:
19-
- uses: actions/checkout@v4
20-
- name: Set up Python 3.10
21-
uses: actions/setup-python@v5
22-
with:
23-
python-version: "3.10"
24-
- name: Install dependencies
25-
run: |
26-
python -m pip install --upgrade pip
27-
pip install -q transformers[onnx] transformers[sentencepiece] torch
28-
- name: Hugging Face Model to ONNX
29-
run: |
30-
# Convert Hugging Face Model to ONNX
31-
python -m transformers.onnx --opset 16 --atol 0.005 --feature=token-classification --model=xlm-roberta-large-finetuned-conll03-english onnx_model/
32-
33-
# Upload the ONNX model as an artifact
34-
- name: Upload ONNX model
35-
uses: actions/upload-artifact@v4.3.6
36-
with:
37-
# Artifact name
38-
name: onnx_model # default: artifact
39-
# Files to upload
40-
path: onnx_model/
41-
# Behavior if no files found: warn, error, ignore
42-
if-no-files-found: error
43-
# Expiration in days (1-90, 0 for default)
44-
retention-days: 0
45-
# Compression level (0-9, default: 6)
46-
compression-level: 7
47-
# Overwrite existing artifact (default: false)
48-
overwrite: true
49-
50-
# Build Java application with Gradle
51-
build-java:
52-
runs-on: ubuntu-latest
53-
permissions:
54-
contents: read
55-
needs: convert-model-to-onnx
56-
57-
steps:
58-
- uses: actions/checkout@v4
59-
# Set up JDK 17
60-
- name: Set up JDK 17
61-
uses: actions/setup-java@v4
62-
with:
63-
java-version: "17"
64-
distribution: "temurin"
65-
66-
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
67-
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
68-
- name: Setup Gradle
69-
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
70-
71-
- name: Download ONNX model from Artifact
72-
uses: actions/download-artifact@v4.1.8
73-
with:
74-
name: onnx_model
75-
path: raw-files # path to download the artifact to
76-
run-id: ${{ github.run_id }}
77-
78-
- name: See artifact contents
79-
run: tree raw-files
80-
81-
# This job is responsible for generating and submitting a dependency graph for the project.
82-
# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies.
83-
# See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md
84-
dependency-submission:
85-
runs-on: ubuntu-latest
86-
permissions:
87-
contents: write
88-
89-
steps:
90-
- uses: actions/checkout@v4
91-
92-
- name: Set up JDK 17
93-
uses: actions/setup-java@v4
94-
with:
95-
java-version: "17"
96-
distribution: "temurin"
97-
98-
- name: Generate and submit dependency graph
99-
uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
1+
# This workflow converts a Hugging Face model to ONNX format, builds a Java application with Gradle,
2+
# and generates and submits a dependency graph for the project.
3+
name: Java application
4+
5+
on:
6+
push:
7+
branches: ["main"]
8+
pull_request:
9+
branches: ["main"]
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
convert-model-to-onnx:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
- name: Set up Python 3.10
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: "3.10"
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install -q transformers[onnx] transformers[sentencepiece] torch
28+
- name: Hugging Face Model to ONNX
29+
run: |
30+
# Convert Hugging Face Model to ONNX
31+
python -m transformers.onnx --opset 16 --atol 0.005 --feature=token-classification --model=xlm-roberta-large-finetuned-conll03-english onnx_model/
32+
33+
# Upload the ONNX model as an artifact
34+
- name: Upload ONNX model
35+
uses: actions/upload-artifact@v4.3.6
36+
with:
37+
# Artifact name
38+
name: onnx_model # default: artifact
39+
# Files to upload
40+
path: onnx_model/
41+
# Behavior if no files found: warn, error, ignore
42+
if-no-files-found: error
43+
# Expiration in days (1-90, 0 for default)
44+
retention-days: 0
45+
# Compression level (0-9, default: 6)
46+
compression-level: 7
47+
# Overwrite existing artifact (default: false)
48+
overwrite: true
49+
50+
# Build Java application with Gradle
51+
build-java:
52+
runs-on: ubuntu-latest
53+
permissions:
54+
contents: read
55+
needs: convert-model-to-onnx
56+
57+
steps:
58+
- uses: actions/checkout@v4
59+
# Set up JDK 17
60+
- name: Set up JDK 17
61+
uses: actions/setup-java@v4
62+
with:
63+
java-version: "17"
64+
distribution: "temurin"
65+
66+
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
67+
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
68+
- name: Setup Gradle
69+
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
70+
71+
- name: Download ONNX model from Artifact
72+
uses: actions/download-artifact@v4.1.8
73+
with:
74+
name: onnx_model
75+
path: raw-files/onnx # path to download the artifact to
76+
run-id: ${{ github.run_id }}
77+
78+
- name: See artifact contents
79+
run: tree raw-files
80+
- name: Download the tokenizer.json file
81+
run: |
82+
wget "https://huggingface.co/xlm-roberta-large-finetuned-conll03-english/resolve/main/tokenizer.json" \
83+
-O raw-files/tokenizer.json
84+
# Build the Java application with Gradle
85+
- name: Build Gradle
86+
run: ./gradlew build
87+
# will run the application Main.java file
88+
- name: Run Gradle
89+
run: ./gradlew run
90+
91+
# This job is responsible for generating and submitting a dependency graph for the project.
92+
# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies.
93+
# See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md
94+
dependency-submission:
95+
runs-on: ubuntu-latest
96+
permissions:
97+
contents: write
98+
99+
steps:
100+
- uses: actions/checkout@v4
101+
102+
- name: Set up JDK 17
103+
uses: actions/setup-java@v4
104+
with:
105+
java-version: "17"
106+
distribution: "temurin"
107+
108+
- name: Generate and submit dependency graph
109+
uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0

0 commit comments

Comments
 (0)