Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Fixes deprecation warning in MiniGo #221

Merged
merged 3 commits into from
Nov 12, 2019

Conversation

valeriyvan
Copy link
Contributor

No description provided.

@BradLarson
Copy link
Contributor

You may have seen this due to a slight lag in the availability of new toolchains, but the use of scalars for epsilon and momentum was just changed yesterday in PR #220 and a matching PR in swift-apis: tensorflow/swift-apis#525

This is by design, and should pass compilation once the new swift-apis changes are in the nightly toolchains.

@@ -54,7 +54,7 @@ struct ConvBN: Layer {
// TODO(jekbradbury): thread through bias and affine boolean arguments
// (behavior is correct for inference but this should be changed for training)
self.conv = Conv2D(filterShape: filterShape, strides: strides, padding: padding)
self.norm = BatchNorm(featureCount: filterShape.3, momentum: 0.95, epsilon: 1e-5)
self.norm = BatchNorm(featureCount: filterShape.3, momentum: Tensor<Float>(0.95), epsilon: Tensor<Float>(1e-5))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please revert this change? As #221 (comment) explains: momentum and epsilon now have type Scalar.

Ubuntu nightly toolchains should already have this change.
A new macOS toolchain will be released with this change soon.


The other deprecation warning fix is valid!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@valeriyvan valeriyvan changed the title Fixes compile error in MiniGo Fixes deprecation warning in MiniGo Nov 8, 2019
@valeriyvan valeriyvan requested a review from dan-zheng November 8, 2019 18:09
@dan-zheng
Copy link
Member

CI shows more warnings, could you please fix those as well?

/swift-models/Transformer/PythonCheckpointReader.swift:39:12: warning: 'Raw' is deprecated: 'Raw' has been renamed to '_Raw' to indicate that it is not a guaranteed/stable API.
    return Raw.restoreV2(prefix: StringTensor(path),
           ^
/swift-models/Transformer/PythonCheckpointReader.swift:39:12: note: use '_Raw' instead
    return Raw.restoreV2(prefix: StringTensor(path),
           ^~~
           _Raw
/swift-models/Transformer/PythonCheckpointReader.swift:76:22: error: cannot convert value of type 'Tensor<Double>' to expected argument type 'Scalar'
            epsilon: Tensor(1e-5))
                     ^
                                  as! Scalar
[18/69] Merging module Gym-Blackjack
[19/69] Compiling MiniGo MCTSNode.swift
[20/69] Compiling MiniGo MCTSRandomPredictor.swift
[23/69] Compiling MiniGo GoModel.swift
/swift-models/MiniGo/Models/GoModel.swift:57:21: error: cannot invoke initializer for type 'BatchNorm<_>' with an argument list of type '(featureCount: Int, momentum: Tensor<Float>, epsilon: Tensor<Float>)'
        self.norm = BatchNorm(
                    ^
/swift-models/MiniGo/Models/GoModel.swift:57:21: note: expected an argument list of type '(featureCount: Int, axis: Int, momentum: Scalar, epsilon: Scalar)'
        self.norm = BatchNorm(
                    ^
[24/69] Compiling MiniGo MCTSPredictor.swift
[25/69] Compiling MiniGo MCTSModelBasePredictor.swift
/swift-models/MiniGo/Strategies/MCTS/MCTSModelBasePredictor.swift:122:30: warning: 'transposed(withPermutations:)' is deprecated: renamed to 'transposed(permutation:)'
        return featureTensor.transposed(withPermutations: 1, 2, 0)
                             ^
/swift-models/MiniGo/Strategies/MCTS/MCTSModelBasePredictor.swift:122:30: note: use 'transposed(permutation:)' instead
        return featureTensor.transposed(withPermutations: 1, 2, 0)
                             ^~~~~~~~~~ ~~~~~~~~~~~~~~~~
                             transposed permutation
[27/69] Compiling MiniGo PythonCheckpointReader.swift
/swift-models/MiniGo/Models/PythonCheckpointReader.swift:31:16: warning: 'Raw' is deprecated: 'Raw' has been renamed to '_Raw' to indicate that it is not a guaranteed/stable API.
        return Raw.restoreV2(prefix: StringTensor(path),
               ^
/swift-models/MiniGo/Models/PythonCheckpointReader.swift:31:16: note: use '_Raw' instead
        return Raw.restoreV2(prefix: StringTensor(path),
               ^~~
               _Raw
/swift-models/Transformer/main.swift:56:14: warning: 'Raw' is deprecated: 'Raw' has been renamed to '_Raw' to indicate that it is not a guaranteed/stable API.
    tokens = Raw.multinomial(logits: lastLogit.squeezingShape(at: 1), numSamples: Tensor<Int32>(1))
             ^
/swift-models/Transformer/main.swift:56:14: note: use '_Raw' instead
    tokens = Raw.multinomial(logits: lastLogit.squeezingShape(at: 1), numSamples: Tensor<Int32>(1))
             ^~~
             _Raw
/swift-models/Datasets/CIFAR10/CIFAR10.swift:116:44: warning: 'transposed(withPermutations:)' is deprecated: renamed to 'transposed(permutation:)'
    let imageTensor = Tensor<Float>(images.transposed(withPermutations: [0, 2, 3, 1]))
                                           ^
/swift-models/Datasets/CIFAR10/CIFAR10.swift:116:44: note: use 'transposed(permutation:)' instead
    let imageTensor = Tensor<Float>(images.transposed(withPermutations: [0, 2, 3, 1]))
                                           ^~~~~~~~~~ ~~~~~~~~~~~~~~~~
                                           transposed permutation
/swift-models/Datasets/CIFAR10/CIFAR10.swift:128:16: warning: 'Raw' is deprecated: 'Raw' has been renamed to '_Raw' to indicate that it is not a guaranteed/stable API.
        label: Raw.concat(concatDim: Tensor<Int32>(0), data.map { $0.label }),
               ^
/swift-models/Datasets/CIFAR10/CIFAR10.swift:128:16: note: use '_Raw' instead
        label: Raw.concat(concatDim: Tensor<Int32>(0), data.map { $0.label }),
               ^~~
               _Raw
/swift-models/Datasets/CIFAR10/CIFAR10.swift:129:15: warning: 'Raw' is deprecated: 'Raw' has been renamed to '_Raw' to indicate that it is not a guaranteed/stable API.
        data: Raw.concat(concatDim: Tensor<Int32>(0), data.map { $0.data })
              ^
/swift-models/Datasets/CIFAR10/CIFAR10.swift:129:15: note: use '_Raw' instead
        data: Raw.concat(concatDim: Tensor<Int32>(0), data.map { $0.data })
              ^~~
              _Raw
[31/70] Merging module Gym-CartPole
[32/70] Wrapping AST for Gym-CartPole for debugging
/swift-models/Transformer/Model.swift:95:16: warning: 'Raw' is deprecated: 'Raw' has been renamed to '_Raw' to indicate that it is not a guaranteed/stable API.
    let mask = Raw.matrixBandPart(
               ^
/swift-models/Transformer/Model.swift:95:16: note: use '_Raw' instead
    let mask = Raw.matrixBandPart(
               ^~~
               _Raw
/swift-models/Transformer/Model.swift:141:37: warning: 'transposed(withPermutations:)' is deprecated: renamed to 'transposed(permutation:)'
    let movedToFront = splitLastDim.transposed(withPermutations: 0, 2, 1, 3)
                                    ^
/swift-models/Transformer/Model.swift:141:37: note: use 'transposed(permutation:)' instead
    let movedToFront = splitLastDim.transposed(withPermutations: 0, 2, 1, 3)
                                    ^~~~~~~~~~ ~~~~~~~~~~~~~~~~
                                    transposed permutation
/swift-models/Transformer/Model.swift:152:37: warning: 'transposed(withPermutations:)' is deprecated: renamed to 'transposed(permutation:)'
    let movedToBack = splitFirstDim.transposed(withPermutations: 0, 2, 1, 3)
                                    ^
/swift-models/Transformer/Model.swift:152:37: note: use 'transposed(permutation:)' instead
    let movedToBack = splitFirstDim.transposed(withPermutations: 0, 2, 1, 3)
                                    ^~~~~~~~~~ ~~~~~~~~~~~~~~~~
                                    transposed permutation
/swift-models/Transformer/Model.swift:176:16: warning: 'Raw' is deprecated: 'Raw' has been renamed to '_Raw' to indicate that it is not a guaranteed/stable API.
        return Raw.concatV2([seed.query, seed.key, seed.value], axis: Tensor<Int32>(2))
               ^
/swift-models/Transformer/Model.swift:176:16: note: use '_Raw' instead
        return Raw.concatV2([seed.query, seed.key, seed.value], axis: Tensor<Int32>(2))
               ^~~
               _Raw
/swift-models/Transformer/Model.swift:230:77: error: cannot convert value of type 'Tensor<Float>' to expected argument type 'Float'
        selfAttentionNorm = LayerNorm(featureCount: size, axis: 2, epsilon: Tensor<Float>(1e-5))
                                                                            ^
/swift-models/Transformer/Model.swift:233:75: error: cannot convert value of type 'Tensor<Float>' to expected argument type 'Float'
        feedForwardNorm = LayerNorm(featureCount: size, axis: 2, epsilon: Tensor<Float>(1e-5))
                                                                          ^
[35/71] Linking Gym-CartPole
[37/71] Merging module Catch
/swift-models/Support/Image.swift:40:26: warning: 'Raw' is deprecated: 'Raw' has been renamed to '_Raw' to indicate that it is not a guaranteed/stable API.
        let loadedFile = Raw.readFile(filename: StringTensor(url.absoluteString))
                         ^
/swift-models/Support/Image.swift:40:26: note: use '_Raw' instead
        let loadedFile = Raw.readFile(filename: StringTensor(url.absoluteString))
                         ^~~
                         _Raw
/swift-models/Support/Image.swift:41:26: warning: 'Raw' is deprecated: 'Raw' has been renamed to '_Raw' to indicate that it is not a guaranteed/stable API.
        let loadedJpeg = Raw.decodeJpeg(contents: loadedFile, channels: 3, dctMethod: "")
                         ^
/swift-models/Support/Image.swift:41:26: note: use '_Raw' instead
        let loadedJpeg = Raw.decodeJpeg(contents: loadedFile, channels: 3, dctMethod: "")
                         ^~~
                         _Raw
/swift-models/Support/Image.swift:44:23: warning: 'Raw' is deprecated: 'Raw' has been renamed to '_Raw' to indicate that it is not a guaranteed/stable API.
                data: Raw.reverse(loadedJpeg, dims: Tensor<Bool>([false, false, false, true])))
                      ^
/swift-models/Support/Image.swift:44:23: note: use '_Raw' instead
                data: Raw.reverse(loadedJpeg, dims: Tensor<Bool>([false, false, false, true])))
                      ^~~
                      _Raw
/swift-models/Support/Image.swift:62:27: warning: 'Raw' is deprecated: 'Raw' has been renamed to '_Raw' to indicate that it is not a guaranteed/stable API.
        let encodedJpeg = Raw.encodeJpeg(
                          ^
/swift-models/Support/Image.swift:62:27: note: use '_Raw' instead
        let encodedJpeg = Raw.encodeJpeg(
                          ^~~
                          _Raw
/swift-models/Support/Image.swift:64:9: warning: 'Raw' is deprecated: 'Raw' has been renamed to '_Raw' to indicate that it is not a guaranteed/stable API.
        Raw.writeFile(filename: StringTensor(url.absoluteString), contents: encodedJpeg)
        ^
/swift-models/Support/Image.swift:64:9: note: use '_Raw' instead
        Raw.writeFile(filename: StringTensor(url.absoluteString), contents: encodedJpeg)
        ^~~
        _Raw
/swift-models/Support/Image.swift:71:25: warning: 'Raw' is deprecated: 'Raw' has been renamed to '_Raw' to indicate that it is not a guaranteed/stable API.
                tensor: Raw.resizeBilinear(
                        ^
/swift-models/Support/Image.swift:71:25: note: use '_Raw' instead
                tensor: Raw.resizeBilinear(
                        ^~~
                        _Raw
/swift-models/Support/Image.swift:76:25: warning: 'Raw' is deprecated: 'Raw' has been renamed to '_Raw' to indicate that it is not a guaranteed/stable API.
                tensor: Raw.resizeBilinear(
                        ^
/swift-models/Support/Image.swift:76:25: note: use '_Raw' instead
                tensor: Raw.resizeBilinear(
                        ^~~
                        _Raw
[39/72] Wrapping AST for Gym-FrozenLake for debugging
[40/72] Wrapping AST for Catch for debugging
[41/72] Wrapping AST for Gym-Blackjack for debugging
[42/72] Merging module ModelSupport
[43/72] Wrapping AST for ModelSupport for debugging
[44/72] Linking Gym-FrozenLake
[45/72] Linking Gym-Blackjack
[46/72] Linking Catch
/swift-models/Datasets/MNIST/MNIST.swift:107:22: warning: 'transposed(withPermutations:)' is deprecated: renamed to 'transposed(permutation:)'
                    .transposed(withPermutations: [0, 2, 3, 1]) / 255,  // NHWC
                     ^
/swift-models/Datasets/MNIST/MNIST.swift:107:22: note: use 'transposed(permutation:)' instead
                    .transposed(withPermutations: [0, 2, 3, 1]) / 255,  // NHWC
                     ^~~~~~~~~~ ~~~~~~~~~~~~~~~~
                     transposed permutation
[48/73] Merging module Datasets
/swift-models/Transformer/Operators.swift:40:12: warning: 'Raw' is deprecated: 'Raw' has been renamed to '_Raw' to indicate that it is not a guaranteed/stable API.
    return Raw.batchMatMul(left, right, adjX: adjointLeft, adjY: adjointRight)
           ^
/swift-models/Transformer/Operators.swift:40:12: note: use '_Raw' instead
    return Raw.batchMatMul(left, right, adjX: adjointLeft, adjY: adjointRight)
           ^~~
           _Raw


[ID: 8456322] Build finished after 244 secs, exit value: 1


Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.

@BradLarson
Copy link
Contributor

To make things easier to pull this in, I've gone ahead and addressed the other deprecation warnings in PR #223. Once we bring these two in, that should take care of those warnings.

@dan-zheng dan-zheng merged commit 8253c35 into tensorflow:master Nov 12, 2019
Copy link
Member

@dan-zheng dan-zheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @valeriyvan!

BradLarson added a commit that referenced this pull request Nov 22, 2019
* Use PascalCase for all Swift source files (#152)

Except `main.swift` files which are the entry points for executables.

Running the following command does not produce any output:

`find . -type f -name "[[:lower:]]*.swift" | rg --pcre2 "^(?!.*(main.swift))"`

Resolves #133.

* Load config variable from `hparams.json` file so that Transformer can work with the bigger GPT-2 models (It is called "staged release". as of now, only 117M and 345M are available). (#154)

* Style fixes from #154 (#155)

* A few quick fixes to help unbreak swift-models. (#160)

* Unbreak models by inserting `.call`. (#161)

See https://bugs.swift.org/browse/TF-516 for additional context.

* s/CotangentVector/TangentVector/g (#162)

* Add MNIST test set evaluation and change hyperparameters. (#163)

- Add MNIST test set evaluation.
- The batch size and the optimizer are changed to `128` and `Adam`, respectively, based on test set evaluation results. Tested with higher batch sizes [256, 512], but found no improvement in performance.

* Updated models to use revised name for callable (SE-0253), fixed a few issues caused by `swift-apis` changes. (#166)

* Updated Transformer and MNIST models to work with 2019-06-04 development snapshot.
* Updated other models.
* Updated ResNet to work with 2019-06-04 development snapshot.
* Updated Catch and CIFAR models.
* Added a method to satisfy TensorGroup protocol that can pass build.

* transformer: upstream api changes (#171)

* rebuild resnet block based approach (#170)

* add gym blackjack qlearning demo (#173)

* Make 'GoModel' stored properties be variables. (#174)

New 'Differentiable' derived conformances will not include constant properties in the tangent space.

* Added .swift-format and updated .gitignore for Xcode 11's SwiftPM support. (#176)

This replicates the following pull request on swift-apis: tensorflow/swift-apis#374 , adding a `swift-format` configuration file. Note the cautions indicated in that pull request around use of `swift-format` at present.

This also adds a .gitignore line to prevent Xcode 11's new SwiftPM support from adding supporting files to the repository.

* Replaced Python with Swift in CIFAR10 dataset loading (#178)

* Replaced all Python code in the CIFAR10 and ResNet examples, removing Python 3 dependency.

* Needed to import FoundationNetworking on Linux.

* Added a check for FoundationNetworking, added an early exit for cached directory check.

* Removed macOS availability check by targeting 10.13 in the package.

* Style and formatting fixes.

* Removed no-longer-needed _tensorHandles and supporting code.

* Replace Autoencoder's tanh activation with sigmoid (#180)

* Add GAN Example (#181)

* Add GAN Example

* Remove do blocks

* Replace lrelu with closure

* Remove typealiases

* Add comment

* Remove labels in GAN example

* Rename variables

* Code formatting, update comments

* Fix: latentDim -> latentSize

* Add spaces around *

* Code formatting, rename loss functions

* Fix: generatorLossFunc -> generatorLoss

* Break lines to make it fit within 100 columns

* Update comments

* Rename plot->plotImage, imageGrid->gridImage, Code formatting

* Refactor: Label creation

* Update comment

* Remove type parameter, empty line

* Update readme

* nightlies URL: s4tf-kokoro-artifact-testing => swift-tensorflow-artifacts (#183)

* First steps in repository reorganization: extracting common MNIST dataset code (#182)

* Extracted MNIST dataset, created LeNet network, added example combining the two.

* Extracted redundant MNIST loading code from GAN and Autoencoder examples, replaced with central MNIST dataset.

* Renamed input parameters and applied standard formatting style to MNIST.

* Punctuation correction.

Co-Authored-By: Richard Wei <[email protected]>

* README formatting update.

Co-Authored-By: Richard Wei <[email protected]>

* Renamed trainImages -> trainingImages, corrected Python package names, formatted Package.swift.

* Update Dockerfile to install Python libraries (#184)

* Delete helpers.swift (#187)

This file is no longer needed apple/swift #26023 and may be causing the segfault reported in swift-apis #186.

* Continuing repository reorganization: extracting common CIFAR-10 and ResNet code (#185)

* Extracted CIFAR-10 dataset and ResNet models into respective modules.

* Minor formatting fixes.

* Mirroring PR #187.

* [Models] Fix enumeration of blocks in `ResidualBasicBlockStack` `init` (#192)

* [Models] Fix enumeration of blocks in `ResidualBasicBlockStack` initialization

* Start range at

* Update ranges

* SqueezeNet Implementation (#189)

* Add files via upload

* Implemented requested changes

Corrected formatting mistakes, used dropout correctly, removed the hard coded number of classes and improved overall readability.

* Update SqeezeNet.swift

Renamed numClasses to classCount and limited all lines to a size of 100.

* WideResNet - fix widenFactor and match model to citation (#193)

* add identity connections to WideResNet

* rename preact1 for clarity

* remove extra relu, add dropout

* fix declarartion

* skip dropout in expansion blocks

* remove enum, res layers to one line

* Removal of deprecated allDifferentiableVariables. (#194)

* Add JPEG loading / saving via Raw TF operations, removing Matplotlib dependencies (#188)

* Added an Image struct as a wrapper for JPEG loading / saving, removed matplotlib dependency from GAN and Autoencoder examples using this.

* Formatting update for Autoencoder.

* Bring this inline with current API.

* Made saveImage() a throwing function, improved formatting.

* Changed function parameter.

* Convert MNIST classifier to use sequential (#200)

* Convert MNIST classifier to use sequential

* Review Changes

* Remove ImageClassification Models

* Convert Autoencoder and Catch to use Sequential (#203)

Partially fixes #202.

* Adding shape-based inference tests for all image classification models (#198)

* Implemented inference tests with random tensors and starting weights for all classification models.

* Made sure tests ran on Linux, reshaped output of SqueezeNet to match other classification models.

* WideResNet is expressed in terms of CIFAR10, so altered the inputs and outputs appropriately.

* Wrapping the reshaping line in SqueezeNet.

* Reset ownership.

* Reworked TensorShape initializers to use array literals.

* Minor formatting tweak to SqueezeNet.

* Update deprecated APIs in Catch (#205)

[swift-apis/#497](tensorflow/swift-apis#497) removes deprecated apis, now that we are moving onward to v0.5. This PR updates the catch file which uses a deprecated dense layer.

* Update squeezenet and add V1.1 version (#204)

* Update squeezenet and add V1.1 version

* value error

* Update tests

* review changes

* Fix '@noDerivative' warnings. (#208)

* Indentation and formatting fixes in CartPole (#214)

* DenseNet Implementaion (#213)

* Create DenseNet.swift

Implementation for the DenseNet Architecture

* Added test for DenseNet

* Fixed Typo

* Refractored the code

* Updated ConvPair description

Co-Authored-By: Richard Wei <[email protected]>

* Fixed comment

Co-Authored-By: Richard Wei <[email protected]>

* Fixed typos, and improved code quality

* Removed extra whitespace and '\'

* Used 3 '/' for documentation and removed return

* Renamed DenseNet to DenseNet121

* Renamed tests

* Updated names

* Renamed all DenseNet identifiers to DenseNet121

* Download MNIST dataset from remote URL (#215)

This PR is intended to fix the second item listed in [this issue](#206):

> it currently relies on hardcoded paths, which will break if you take the dataset outside of that project and try to use it in something like Colab.

In this PR, the datasets are instead downloaded from a remote URL, so they are not fragile with respect to the current working directory where the MNIST dataset is instantiated from.

The implementation in this PR brings the MINST dataset in line with how the CFAR10 dataset is loaded.

* use enable in _vjpCausallyMasked (#218)

Fixes #217

* Change momentum and epsilon properties to scalars. (#220)

* Uses switch instead of ifs (#219)

* Fixes deprecation warning in MiniGo (#221)

* Fixing deprecation warnings on all but the MiniGo example. (#223)

* Initial training and inference benchmarks (#222)

* Initial implementation of training and inference benchmarks.

* Resolved a typechecker issue.

* Added a Readme.

* Added copyright headers.

* Reworked the benchmarking functions to use a single function that is specialized via enums.

* Reworked the model-specific benchmark into general inference and training cases that can work on arbitrary image classification models.

* Restructured BenchmarkResults to be a plain collection of timings, with specific benchmark processing working on that.

* Rename interpretTimings to interpretedTimings.

Co-Authored-By: Dan Zheng <[email protected]>

* Change reference to interpretedTimings later.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants