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

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

Merged
merged 1 commit into from
May 20, 2019
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
9 changes: 3 additions & 6 deletions MiniGo/Models/PythonCheckpointReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ public class PythonCheckpointReader {
let countSuffix = layerCounts[layerName] == nil ? "" : "_\(layerCounts[layerName]!)"
let tensorName = layerName + countSuffix + "/" + weightName
// TODO(jekbradbury): support variadic dtype attrs in RawOpsGenerated
return Tensor<Float>(handle: #tfop(
"RestoreV2",
StringTensor(path),
StringTensor([tensorName]),
StringTensor([""]),
dtypes$dtype: [Float.tensorFlowDataType]))
return Raw.restoreV2(prefix: StringTensor(path),
tensorNames: StringTensor([tensorName]),
shapeAndSlices: StringTensor([""]))
}

/// Increments a per-layer counter for variable names in the checkpoint file.
Expand Down
3 changes: 2 additions & 1 deletion Transformer/Operators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import TensorFlow
/// Computes the Gaussian error linear unit (GELU) nonlinear activation function
@differentiable
func gelu<Scalar: TensorFlowFloatingPoint>(_ x: Tensor<Scalar>) -> Tensor<Scalar> {
let polynomial = 0.79788456 * (x + 0.044715 * x * x * x)
let xCubed = x * x * x
let polynomial = 0.79788456 * (x + 0.044715 * xCubed)
return 0.5 * x * (1.0 + tanh(polynomial))
}

Expand Down
9 changes: 3 additions & 6 deletions Transformer/PythonCheckpointReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@ func readTensor<Scalar: TensorFlowScalar>(
scalarType: Scalar.Type
) -> Tensor<Scalar> {
// TODO(jekbradbury): support variadic dtype attrs in RawOpsGenerated
return Tensor(handle: #tfop(
"RestoreV2",
StringTensor(path),
StringTensor([name]),
StringTensor([""]),
dtypes$dtype: [Scalar.tensorFlowDataType]))
return Raw.restoreV2(prefix: StringTensor(path),
tensorNames: StringTensor([name]),
shapeAndSlices: StringTensor([""]))
}

protocol InitializableFromPythonCheckpoint {
Expand Down