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

🚀 feat(examples): make Transformer example very simple #75

Merged
merged 1 commit into from
Mar 17, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.

## [unreleased]

🚀 **examples:** make Transformer example very simple ([#75](https://github.com/owkin/GrAIdient/pull/75))\
🚀 **examples:** adding Transformer training example ([#74](https://github.com/owkin/GrAIdient/pull/74))\
⚙️ **core:** GELU activation function ([#73](https://github.com/owkin/GrAIdient/pull/73))\
🐛 **fix:** update ValueSeq operation ([#72](https://github.com/owkin/GrAIdient/pull/72))\
Expand Down
19 changes: 10 additions & 9 deletions Tests/GrAIExamples/TransformerExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ final class TransformerExample: XCTestCase
var sampler: CIFAR = cifar8
var samples = sampler.getSamples()


for label in 0...1
{
if samples == nil
Expand Down Expand Up @@ -431,13 +430,15 @@ final class TransformerExample: XCTestCase
func test3_UntrainedModel()
{
// Build a model with randomly initialized weights.
let transformer = _buildModel(size: 32,
patch: 16,
nbLayers: 12,
nbHeads: 12,
hiddenDim: 768,
mlpDim: 3072,
mlpActivation: ReLU.str)
let transformer = _buildModel(
size: 32,
patch: 16,
nbLayers: 2,
nbHeads: 2,
hiddenDim: 16,
mlpDim: 32,
mlpActivation: ReLU.str
)

// Initialize for inference.
transformer.initKernel(phase: .Inference)
Expand Down Expand Up @@ -488,7 +489,7 @@ final class TransformerExample: XCTestCase
// Small trick to force full batches throughout the training:
// this enables us to set the ground truth once and for all.
let nbWholeBatches =
cifar8.nbSamples / cifar8.batchSize * cifar8.batchSize
cifar8.nbSamples / cifar8.batchSize * cifar8.batchSize
cifar8.keep(nbWholeBatches)
cifar5.keep(nbWholeBatches)

Expand Down