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

Move gpt model code into a directory #379

Merged
merged 1 commit into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions keras_nlp/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
from keras_nlp.models.bert.bert_models import BertTiny
from keras_nlp.models.bert.bert_preprocessing import BertPreprocessor
from keras_nlp.models.bert.bert_tasks import BertClassifier
from keras_nlp.models.gpt2 import Gpt2Base
from keras_nlp.models.gpt2 import Gpt2Custom
from keras_nlp.models.gpt2 import Gpt2ExtraLarge
from keras_nlp.models.gpt2 import Gpt2Large
from keras_nlp.models.gpt2 import Gpt2Medium
from keras_nlp.models.gpt2.gpt2_models import Gpt2Base
from keras_nlp.models.gpt2.gpt2_models import Gpt2Custom
from keras_nlp.models.gpt2.gpt2_models import Gpt2ExtraLarge
from keras_nlp.models.gpt2.gpt2_models import Gpt2Large
from keras_nlp.models.gpt2.gpt2_models import Gpt2Medium
from keras_nlp.models.roberta import RobertaBase
from keras_nlp.models.roberta import RobertaClassifier
from keras_nlp.models.roberta import RobertaCustom
13 changes: 13 additions & 0 deletions keras_nlp/models/gpt2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2022 The KerasNLP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""GPT-2 model configurable class, preconfigured versions, and task heads."""
"""GPT-2 backbone models."""

import tensorflow as tf
from tensorflow import keras
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for GPT-2 model."""
"""Test for GPT-2 backbone models."""

import os

import tensorflow as tf
from absl.testing import parameterized
from tensorflow import keras

from keras_nlp.models import gpt2
from keras_nlp.models.gpt2.gpt2_models import Gpt2Base
from keras_nlp.models.gpt2.gpt2_models import Gpt2Custom


class Gpt2Test(tf.test.TestCase, parameterized.TestCase):
def setUp(self):
self.model = gpt2.Gpt2Custom(
self.model = Gpt2Custom(
vocabulary_size=1000,
num_layers=2,
num_heads=2,
Expand Down Expand Up @@ -63,22 +64,22 @@ def test_variable_sequence_length_call_gpt2(self):
self.model(input_data)

def test_valid_call_gpt2_base(self):
model = gpt2.Gpt2Base(vocabulary_size=1000, name="gpt2_base_test")
model = Gpt2Base(vocabulary_size=1000, name="gpt2_base_test")
model(self.input_batch)

@parameterized.named_parameters(
("jit_compile_false", False), ("jit_compile_true", True)
)
def test_gpt2_base_compile(self, jit_compile):
model = gpt2.Gpt2Base(vocabulary_size=1000, name="gpt2_base_test")
model = Gpt2Base(vocabulary_size=1000, name="gpt2_base_test")
model.compile(jit_compile=jit_compile)
model.predict(self.input_batch)

@parameterized.named_parameters(
("jit_compile_false", False), ("jit_compile_true", True)
)
def test_gpt2_base_compile_batched_ds(self, jit_compile):
model = gpt2.Gpt2Base(vocabulary_size=1000, name="gpt2_base_test")
model = Gpt2Base(vocabulary_size=1000, name="gpt2_base_test")
model.compile(jit_compile=jit_compile)
model.predict(self.input_dataset)

Expand Down