-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tailor plus tuner integration test (#124)
- Loading branch information
Showing
3 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pytest | ||
import tensorflow as tf | ||
|
||
from finetuner import fit | ||
|
||
|
||
@pytest.fixture | ||
def embed_model(): | ||
return tf.keras.Sequential( | ||
[ | ||
tf.keras.layers.Flatten(input_shape=(128,)), | ||
tf.keras.layers.Dense(256, activation='relu'), | ||
tf.keras.layers.Dense(128, activation='relu'), | ||
tf.keras.layers.Dense(64, activation='relu'), | ||
tf.keras.layers.Dense(32), | ||
] | ||
) | ||
|
||
|
||
def test_tail_and_tune(embed_model, create_easy_data): | ||
data, _ = create_easy_data(10, 128, 1000) | ||
rv = fit( | ||
model=embed_model, | ||
train_data=data, | ||
epochs=5, | ||
to_embedding_model=True, | ||
input_size=128, | ||
output_dim=16, | ||
layer_name='dense_2', | ||
) | ||
assert rv['loss']['train'] | ||
assert rv['metric']['train'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import pytest | ||
import paddle.nn as nn | ||
|
||
from finetuner import fit | ||
|
||
|
||
@pytest.fixture | ||
def embed_model(): | ||
return nn.Sequential( | ||
nn.Flatten(), | ||
nn.Linear(in_features=128, out_features=256), | ||
nn.ReLU(), | ||
nn.Linear(in_features=256, out_features=128), | ||
nn.ReLU(), | ||
nn.Linear(in_features=128, out_features=64), | ||
nn.ReLU(), | ||
nn.Linear(in_features=64, out_features=32), | ||
) | ||
|
||
|
||
def test_tail_and_tune(embed_model, create_easy_data): | ||
data, _ = create_easy_data(10, 128, 1000) | ||
rv = fit( | ||
model=embed_model, | ||
train_data=data, | ||
epochs=5, | ||
to_embedding_model=True, | ||
input_size=(128,), | ||
output_dim=16, | ||
layer_name='linear_4', | ||
) | ||
assert rv['loss']['train'] | ||
assert rv['metric']['train'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import pytest | ||
import torch.nn as nn | ||
|
||
from finetuner import fit | ||
|
||
|
||
@pytest.fixture | ||
def embed_model(): | ||
return nn.Sequential( | ||
nn.Flatten(), | ||
nn.Linear(in_features=128, out_features=256), | ||
nn.ReLU(), | ||
nn.Linear(in_features=256, out_features=128), | ||
nn.ReLU(), | ||
nn.Linear(in_features=128, out_features=64), | ||
nn.ReLU(), | ||
nn.Linear(in_features=64, out_features=32), | ||
) | ||
|
||
|
||
def test_tail_and_tune(embed_model, create_easy_data): | ||
data, _ = create_easy_data(10, 128, 1000) | ||
rv = fit( | ||
model=embed_model, | ||
train_data=data, | ||
epochs=5, | ||
to_embedding_model=True, | ||
input_size=(128,), | ||
output_dim=16, | ||
layer_name='linear_4', | ||
) | ||
assert rv['loss']['train'] | ||
assert rv['metric']['train'] |