tensorflow / swift-models

Models and examples built with Swift for TensorFlow
Apache License 2.0
648 stars 148 forks source link

macOS S4TF 0.11 Build Failure: Function is not Differentiable #713

Closed xanderdunn closed 3 years ago

xanderdunn commented 3 years ago

macOS 11.0.1.

$ which swift
/Library/Developer/Toolchains/swift-tensorflow-RELEASE-0.11.xctoolchain/usr/bin/swift
$ swift --version
Swift version 5.3-dev (LLVM db8896f3f345af2, Swift 61684f62a6132c0)
Target: x86_64-apple-darwin20.1.0
$ git log
commit b599958716ac53fa9de59aff0a9e40d317302fae (HEAD -> master, origin/master, origin/main, origin/HEAD)
Author: xihui-wu <58450438+xihui-wu@users.noreply.github.com>
Date:   Mon Dec 7 13:56:18 2020 -0800

    Refactor LearningRateScheduler (#711)

    Refactor LearningRateScheduler

    Co-authored-by: Dave Abrahams <dabrahams@google.com>
$ swift build
/Users/xander/dev/swift-models/Models/Text/WordSeg/Model.swift:256:4: error: function is not differentiable
  @differentiable
  ~^~~~~~~~~~~~~~
/Users/xander/dev/swift-models/Models/Text/WordSeg/Model.swift:257:15: note: when differentiating this function definition
  public func buildLattice(_ sentence: CharacterSequence, maxLen: Int, device: Device) -> Lattice {
              ^
/Users/xander/dev/swift-models/Models/Text/WordSeg/Model.swift:270:33: note: cannot differentiate unsupported control flow
        if candidate.count != 1 && candidate.last == parameters.alphabet.eos {
                                ^

I'm unable to upgrade to S4TF 0.12 because of this bug, hence compiling with 0.11.

Compiling on Linux with S4TF 0.12 works fine.

BradLarson commented 3 years ago

Unfortunately, there are a few places that incorrectly complain about differentiability in the head of swift-models when using the 0.11 release toolchain. There isn't a great way to work with the latest swift-models and the 0.11 toolchain (you can use the tensorflow-0.11 branch to go to the snapshot of swift-models as of the time we released 0.11, but that will lack functionality we've added since).

That bug's a real bummer, and I don't have a great suggestion for working around this until it's resolved.

xanderdunn commented 3 years ago

Thanks @BradLarson, pegging my dependency to the tensorflow-0.11 branch will be fine for the time being, I'll go ahead and close this.