Skip to content

Commit 9c6ea55

Browse files
fixing tests
1 parent e28cb3a commit 9c6ea55

8 files changed

Lines changed: 67 additions & 20 deletions

File tree

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
run: |
3434
go mod download
3535
- name: Build and run tests
36-
run: make run-tests
36+
run: make run-tests BUILD_TAG=ALL
3737
- name: Install goveralls
3838
run: go install github.com/mattn/goveralls@latest
3939
- name: Send coverage

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
run: |
2424
go mod download
2525
- name: Build and run tests
26-
run: make run-tests
26+
run: make run-tests BUILD_TAG=ALL
2727
- name: Install goveralls
2828
run: go install github.com/mattn/goveralls@latest
2929
- name: Send coverage

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ SHELL := bash
55
all:
66

77
run-tests:
8-
scripts/run-unit-tests.sh
8+
scripts/run-unit-tests.sh $(BUILD_TAG)
99

1010
clean:
1111
rm -r ./testTarget || true

cmd/main_test.go

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ var textClassificationData []byte
1919
//go:embed testData/tokenClassification.jsonl
2020
var tokenClassificationData []byte
2121

22+
const onnxRuntimeSharedLibrary = "/usr/lib64/onnxruntime.so"
23+
2224
func TestTextClassificationCli(t *testing.T) {
2325
app := &cli.App{
2426
Name: "hugot",
@@ -43,7 +45,11 @@ func TestTextClassificationCli(t *testing.T) {
4345
check(t, err)
4446
}()
4547

46-
args := append(baseArgs, "run", fmt.Sprintf("--input=%s", testDataDir), fmt.Sprintf("--model=%s", testModel), "--type=textClassification")
48+
args := append(baseArgs, "run",
49+
fmt.Sprintf("--input=%s", testDataDir),
50+
fmt.Sprintf("--s=%s", onnxRuntimeSharedLibrary),
51+
fmt.Sprintf("--model=%s", testModel),
52+
"--type=textClassification")
4753
if err := app.Run(args); err != nil {
4854
check(t, err)
4955
}
@@ -69,8 +75,12 @@ func TestTokenClassificationCli(t *testing.T) {
6975
check(t, err)
7076
}()
7177

72-
args := append(baseArgs, "run", fmt.Sprintf("--input=%s", path.Join(testDataDir, "test-token-classification.jsonl")),
73-
fmt.Sprintf("--model=%s", testModel), "--type=tokenClassification", fmt.Sprintf("--output=%s", testDataDir))
78+
args := append(baseArgs, "run",
79+
fmt.Sprintf("--input=%s", path.Join(testDataDir, "test-token-classification.jsonl")),
80+
fmt.Sprintf("--s=%s", onnxRuntimeSharedLibrary),
81+
fmt.Sprintf("--model=%s", testModel),
82+
"--type=tokenClassification",
83+
fmt.Sprintf("--output=%s", testDataDir))
7484
if err := app.Run(args); err != nil {
7585
check(t, err)
7686
}
@@ -86,9 +96,7 @@ func TestFeatureExtractionCli(t *testing.T) {
8696
Commands: []*cli.Command{runCommand},
8797
}
8898
baseArgs := os.Args[0:1]
89-
90-
testModel := path.Join("../models", "sentence-transformers_all-MiniLM-L6-v2")
91-
99+
testModel := path.Join("../models", "KnightsAnalytics_all-MiniLM-L6-v2")
92100
testDataDir := path.Join(os.TempDir(), "hugoTestData")
93101
err := os.MkdirAll(testDataDir, os.ModePerm)
94102
check(t, err)
@@ -99,9 +107,13 @@ func TestFeatureExtractionCli(t *testing.T) {
99107
check(t, err)
100108
}()
101109

102-
args := append(baseArgs, "run", fmt.Sprintf("--input=%s", path.Join(testDataDir, "test-feature-extraction.jsonl")),
103-
fmt.Sprintf("--model=%s", testModel), fmt.Sprintf("--onnxFilename=%s", "model.onnx"),
104-
"--type=featureExtraction", fmt.Sprintf("--output=%s", testDataDir))
110+
args := append(baseArgs, "run",
111+
fmt.Sprintf("--input=%s", path.Join(testDataDir, "test-feature-extraction.jsonl")),
112+
fmt.Sprintf("--s=%s", onnxRuntimeSharedLibrary),
113+
fmt.Sprintf("--model=%s", testModel),
114+
fmt.Sprintf("--onnxFilename=%s", "model.onnx"),
115+
"--type=featureExtraction",
116+
fmt.Sprintf("--output=%s", testDataDir))
105117
if err := app.Run(args); err != nil {
106118
check(t, err)
107119
}
@@ -136,13 +148,20 @@ func TestModelChain(t *testing.T) {
136148
check(t, util.FileSystem.Delete(context.Background(), util.PathJoinSafe(userFolder, "hugot")))
137149

138150
// try to download the model to hugo folder and run it
139-
args := append(baseArgs, "run", fmt.Sprintf("--input=%s", testDataDir), fmt.Sprintf("--model=%s", "KnightsAnalytics/distilbert-base-uncased-finetuned-sst-2-english"), "--type=textClassification")
151+
args := append(baseArgs, "run",
152+
fmt.Sprintf("--input=%s", testDataDir),
153+
fmt.Sprintf("--s=%s", onnxRuntimeSharedLibrary),
154+
fmt.Sprintf("--model=%s", "KnightsAnalytics/distilbert-base-uncased-finetuned-sst-2-english"),
155+
"--type=textClassification")
140156
if err := app.Run(args); err != nil {
141157
check(t, err)
142158
}
143159

144160
// run it again. This time the model should be read from the hugot folder without re-downloading it.
145-
args = append(baseArgs, "run", fmt.Sprintf("--input=%s", testDataDir), fmt.Sprintf("--model=%s", "KnightsAnalytics/distilbert-base-uncased-finetuned-sst-2-english"), "--type=textClassification")
161+
args = append(baseArgs, "run", fmt.Sprintf("--input=%s", testDataDir),
162+
fmt.Sprintf("--model=%s", "KnightsAnalytics/distilbert-base-uncased-finetuned-sst-2-english"),
163+
fmt.Sprintf("--s=%s", onnxRuntimeSharedLibrary),
164+
"--type=textClassification")
146165
if err := app.Run(args); err != nil {
147166
check(t, err)
148167
}

compose-test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ services:
1313
environment:
1414
- HOST_UID=$host_uid
1515
- CI=$CI
16+
- HUGOT_BUILD_TAG=$HUGOT_BUILD_TAG
1617
command: /run-unit-tests-container.sh
1718
# deploy:
1819
# resources:

hugot_training_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ func TestSemanticSimilarity(t *testing.T) {
1919
t.Fatal(err)
2020
}
2121

22+
modelPath := "./models/KnightsAnalytics_all-MiniLM-L6-v2"
23+
2224
// create a new xla training session. Currently training is only possible by loading an onnx model
2325
// into xla, fine-tuning it with gomlx, and then writing it back to onnx. Hugot deals with the details
2426
// for you here.
2527
session, err := NewXLATrainingSession[*pipelines.FeatureExtractionPipeline](
2628
TrainingConfig{
27-
ModelPath: "./models/sentence-transformers_all-MiniLM-L6-v2",
29+
ModelPath: modelPath,
2830
Dataset: dataset,
2931
Epochs: 1,
3032
Cuda: false,
@@ -62,9 +64,11 @@ func TestSemanticSimilarityCuda(t *testing.T) {
6264
t.Fatal(err)
6365
}
6466

67+
modelPath := "./models/KnightsAnalytics_all-MiniLM-L6-v2"
68+
6569
session, err := NewXLATrainingSession[*pipelines.FeatureExtractionPipeline](
6670
TrainingConfig{
67-
ModelPath: "./models/sentence-transformers_all-MiniLM-L6-v2",
71+
ModelPath: modelPath,
6872
Dataset: dataset,
6973
Epochs: 1,
7074
Cuda: true, // use cuda

scripts/run-unit-tests-container.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,18 @@ set -e
44

55
cd /build && \
66
mkdir -p /test/unit && \
7-
go run ./testData/downloadModels.go && \
8-
gotestsum --junitfile=/test/unit/unit.xml --jsonfile=/test/unit/unit.json -- -tags=ALL -coverprofile=/test/unit/cover.out.pre -race -covermode=atomic ./...
9-
grep -v "downloadModels.go" /test/unit/cover.out.pre > /test/unit/cover.out
10-
rm /test/unit/cover.out.pre
7+
go run ./testData/downloadModels.go
8+
9+
echo HUGOT_BUILD_TAG is "$HUGOT_BUILD_TAG"
10+
11+
if [[ -n $HUGOT_BUILD_TAG ]]; then
12+
echo "running with -tags=ALL"
13+
gotestsum --junitfile=/test/unit/unit.xml --jsonfile=/test/unit/unit.json -- -tags=ALL -coverprofile=/test/unit/cover.out.pre -race -covermode=atomic ./...
14+
else
15+
echo "running without build tags"
16+
gotestsum --junitfile=/test/unit/unit.xml --jsonfile=/test/unit/unit.json -- -coverprofile=/test/unit/cover.out.pre -race -covermode=atomic ./...
17+
fi
18+
19+
grep -v "downloadModels.go" /test/unit/cover.out.pre > /test/unit/cover.out && rm /test/unit/cover.out.pre
1120

1221
echo Done.

scripts/run-unit-tests.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ mkdir -p "$test_folder"
1515
host_uid=$(id -u "$USER")
1616
export host_uid
1717

18+
if [ $# -eq 0 ]; then
19+
echo "running without build tags"
20+
export HUGOT_BUILD_TAG=""
21+
else
22+
first_arg=$1
23+
if [[ $first_arg == "ALL" ]]; then
24+
echo "running with build tag ALL"
25+
export HUGOT_BUILD_TAG="ALL"
26+
else
27+
echo "build tag $first_arg is not supported"
28+
exit 1
29+
fi
30+
fi
31+
1832
# build with compose
1933
docker compose -f "$src_dir/compose-test.yaml" build
2034
echo "Running tests for commit hash: $commit_hash"

0 commit comments

Comments
 (0)