Skip to content

Commit

Permalink
Merge pull request #6 from haifeng-jin/rm
Browse files Browse the repository at this point in the history
removed native pytorch code
  • Loading branch information
haifeng-jin authored May 20, 2024
2 parents 4f1d20e + f9792f0 commit 4fe0fde
Show file tree
Hide file tree
Showing 38 changed files with 40 additions and 744 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.venv
results.txt
*.egg-info
__pycache__
19 changes: 1 addition & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,6 @@ Python package versions for each framework.

## Permission setups

### HuggingFace setup

On the [HuggingFace Gemma model page](https://huggingface.co/google/gemma-7b),
make sure you have accepted the license near the top of the page.

```shell
pip install --upgrade huggingface_hub
```

```shell
huggingface-cli login
```

It may require you to input a token.
[More information about tokens.](https://huggingface.co/docs/hub/en/security-tokens)


### Kaggle setup

On the [Kaggle Gemma model page](https://www.kaggle.com/models/keras/gemma),
Expand Down Expand Up @@ -82,7 +65,7 @@ run `shell/cleanup.sh`.
structured as a Python package. I needs `pip install -e .` before using. Most
of the settings are in `benchmark/__init__.py`. You can run a single benchmark
by calling each script, for example,
`python benchmark/gemma/keras/predict.py results.txt`
`python benchmark/gemma/predict.py results.txt`
* `shell` contains all the shell scripts for benchmarking.
* `requirements` contains the version requirements for the PyPI packages in the
dependencies.
Expand Down
2 changes: 1 addition & 1 deletion benchmark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def append_to_file(file_path, content):

def benchmark(run):
if len(sys.argv) not in (2, 3):
print("Usage: python bert/keras/fit.py <file_path> [batch_size]")
print("Usage: python bert/fit.py <file_path> [batch_size]")
else:
if len(sys.argv) == 3:
batch_size = int(sys.argv[2])
Expand Down
8 changes: 4 additions & 4 deletions benchmark/bert/keras/fit.py → benchmark/bert/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import keras_nlp

import benchmark
from benchmark import keras_utils
from benchmark import utils


def run(batch_size=benchmark.BERT_FIT_BATCH_SIZE):
preprocessor = keras_nlp.models.BertPreprocessor.from_preset(
"bert_base_en", sequence_length=benchmark.BERT_SEQ_LENGTH
)
dataset = keras_utils.get_train_dataset_for_text_classification(
dataset = utils.get_train_dataset_for_text_classification(
preprocessor=preprocessor,
batch_size=batch_size,
seq_len=benchmark.BERT_SEQ_LENGTH,
Expand All @@ -22,10 +22,10 @@ def run(batch_size=benchmark.BERT_FIT_BATCH_SIZE):
model.compile(
loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
optimizer=keras.optimizers.AdamW(),
jit_compile=keras_utils.use_jit(),
jit_compile=utils.use_jit(),
)

return keras_utils.fit(model, dataset)
return utils.fit(model, dataset)


if __name__ == "__main__":
Expand Down
Empty file removed benchmark/bert/keras/__init__.py
Empty file.
8 changes: 4 additions & 4 deletions benchmark/bert/keras/predict.py → benchmark/bert/predict.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import keras_nlp

import benchmark
from benchmark import keras_utils
from benchmark import utils


def run(batch_size=benchmark.BERT_BATCH_SIZE):
preprocessor = keras_nlp.models.BertPreprocessor.from_preset(
"bert_base_en", sequence_length=benchmark.BERT_SEQ_LENGTH
)
dataset = keras_utils.get_train_dataset_for_text_classification(
dataset = utils.get_train_dataset_for_text_classification(
preprocessor=preprocessor,
batch_size=batch_size,
seq_len=benchmark.BERT_SEQ_LENGTH,
Expand All @@ -19,10 +19,10 @@ def run(batch_size=benchmark.BERT_BATCH_SIZE):
preprocessor=None,
)
model.compile(
jit_compile=keras_utils.use_jit(),
jit_compile=utils.use_jit(),
)

return keras_utils.predict(model, dataset)
return utils.predict(model, dataset)


if __name__ == "__main__":
Expand Down
Empty file removed benchmark/bert/torch/__init__.py
Empty file.
52 changes: 0 additions & 52 deletions benchmark/bert/torch/fit.py

This file was deleted.

55 changes: 0 additions & 55 deletions benchmark/bert/torch/predict.py

This file was deleted.

8 changes: 4 additions & 4 deletions benchmark/gemma/keras/fit.py → benchmark/gemma/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import keras_nlp

import benchmark
from benchmark import keras_utils
from benchmark import utils


def get_model():
Expand All @@ -22,17 +22,17 @@ def run(batch_size=benchmark.GEMMA_FIT_BATCH_SIZE):
preprocessor = keras_nlp.models.GemmaCausalLMPreprocessor.from_preset(
"gemma_7b_en", sequence_length=benchmark.GEMMA_SEQ_LENGTH
)
dataset = keras_utils.get_train_dataset_for_text_gen(
dataset = utils.get_train_dataset_for_text_gen(
preprocessor, batch_size, seq_len=benchmark.GEMMA_SEQ_LENGTH
)
model = get_model()

model.compile(
loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
optimizer=keras.optimizers.AdamW(),
jit_compile=keras_utils.use_jit(),
jit_compile=utils.use_jit(),
)
return keras_utils.fit(model, dataset)
return utils.fit(model, dataset)


if __name__ == "__main__":
Expand Down
Empty file removed benchmark/gemma/keras/__init__.py
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import keras_nlp

import benchmark
from benchmark import keras_utils
from benchmark import utils


def run(batch_size=benchmark.GEMMA_BATCH_SIZE):
Expand All @@ -12,7 +12,7 @@ def run(batch_size=benchmark.GEMMA_BATCH_SIZE):
keras.mixed_precision.set_global_policy(benchmark.FLOAT_A100)
model = keras_nlp.models.GemmaCausalLM.from_preset("gemma_7b_en")
model.compile(sampler="greedy")
return keras_utils.generate(
return utils.generate(
model=model,
batch_size=batch_size,
max_length=benchmark.GEMMA_MAX_LENGTH,
Expand Down
Empty file removed benchmark/gemma/torch/__init__.py
Empty file.
56 changes: 0 additions & 56 deletions benchmark/gemma/torch/fit.py

This file was deleted.

28 changes: 0 additions & 28 deletions benchmark/gemma/torch/predict.py

This file was deleted.

8 changes: 4 additions & 4 deletions benchmark/mistral/keras/fit.py → benchmark/mistral/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import keras_nlp

import benchmark
from benchmark import keras_utils
from benchmark import utils


def get_model():
Expand All @@ -23,17 +23,17 @@ def run(batch_size=benchmark.MISTRAL_FIT_BATCH_SIZE):
"mistral_7b_en",
sequence_length=benchmark.MISTRAL_SEQ_LENGTH,
)
dataset = keras_utils.get_train_dataset_for_text_gen(
dataset = utils.get_train_dataset_for_text_gen(
preprocessor, batch_size, seq_len=benchmark.MISTRAL_SEQ_LENGTH
)
model = get_model()

model.compile(
loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
optimizer=keras.optimizers.AdamW(),
jit_compile=keras_utils.use_jit(),
jit_compile=utils.use_jit(),
)
return keras_utils.fit(model, dataset)
return utils.fit(model, dataset)


if __name__ == "__main__":
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import keras_nlp

import benchmark
from benchmark import keras_utils
from benchmark import utils


def run(batch_size=benchmark.MISTRAL_BATCH_SIZE):
Expand All @@ -12,7 +12,7 @@ def run(batch_size=benchmark.MISTRAL_BATCH_SIZE):
keras.mixed_precision.set_global_policy(benchmark.FLOAT_A100)
model = keras_nlp.models.MistralCausalLM.from_preset("mistral_7b_en")
model.compile(sampler="greedy")
return keras_utils.generate(
return utils.generate(
model=model,
batch_size=batch_size,
max_length=benchmark.MISTRAL_MAX_LENGTH,
Expand Down
Empty file.
Loading

0 comments on commit 4fe0fde

Please sign in to comment.