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

[SR-9718] [AD] Generic differentiation assertion in isLegalAggregates #52153

Closed
rxwei opened this issue Jan 21, 2019 · 1 comment
Closed

[SR-9718] [AD] Generic differentiation assertion in isLegalAggregates #52153

rxwei opened this issue Jan 21, 2019 · 1 comment
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. swift for tensorflow

Comments

@rxwei
Copy link
Member

rxwei commented Jan 21, 2019

Previous ID SR-9718
Radar None
Original Reporter @rxwei
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Swift for TensorFlow
Labels Bug
Assignee @dan-zheng
Priority Medium

md5: 002bd130a312e59943d933836632b667

Issue Description:

import TensorFlow
public protocol Layer: Differentiable & KeyPathIterable
    where AllDifferentiableVariables: KeyPathIterable {
    /// The input type of the layer.
    associatedtype Input: Differentiable
    /// The output type of the layer.
    associatedtype Output: Differentiable

    /// Returns the output obtained from applying to an input.
    @differentiable(wrt: (self, input))
    func applied(to input: Input) -> Output
}

public extension Layer {
    func valueWithPullback(at input: Input)
        -> (output: Output,
            pullback: (Output.CotangentVector)
                -> (layerGradient: CotangentVector, inputGradient: Input.CotangentVector)) {
        let (out, pullback) = _valueWithPullback(at: self, input, in: Self.applied(to:))
        return (out, pullback)
    }
}

public struct Dense<Scalar>: Layer
    where Scalar : FloatingPoint & Differentiable & TensorFlowScalar {
    public var weight: Tensor<Scalar>
    public var bias: Tensor<Scalar>

    @differentiable(wrt: (self, input))
    public func applied(to input: Tensor<Scalar>) -> Tensor<Scalar> {
        return matmul(input, weight) + bias
    }
}

public extension Dense where Scalar : BinaryFloatingPoint,
                             Scalar.RawSignificand : FixedWidthInteger {
    init(inputSize: Int, outputSize: Int) {
        self.init(weight: Tensor(randomNormal: [Int32(inputSize), Int32(outputSize)]),
                  bias: Tensor(randomNormal: [Int32(outputSize)]))
    }
}
Assertion failed: (isLegalAggregate(elements, type)), function getAggregate, file /usr/local/src/swift-build/swift/lib/SILOptimizer/Mandatory/Differentiation.cpp, line 2631.
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-tensorflow-DEVELOPMENT-2019-01-21-a.xctoolchain/usr/bin/swift -frontend -c -primary-file generic-layer.swift -target x86_64-apple-darwin18.2.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -color-diagnostics -module-name main -o /var/folders/lt/hxxf77kd79q3cszbw48rrd_m0000gn/T/generic-layer-2edf0e.o
1.  While running pass #&#8203;339 SILModuleTransform "Differentiation".
0  swift                    0x0000000106455048 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x00000001064542c5 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x0000000106455652 SignalHandler(int) + 258
3  libsystem_platform.dylib 0x00007fff72317b3d _sigtramp + 29
4  libsystem_platform.dylib 0x000000010b0d7938 _sigtramp + 2564554264
5  libsystem_c.dylib        0x00007fff721d51c9 abort + 127
6  libsystem_c.dylib        0x00007fff7219d868 basename_r + 0
7  swift                    0x00000001032ef441 (anonymous namespace)::AdjointValue::getAggregate(swift::SILType, llvm::ArrayRef<(anonymous namespace)::AdjointValue>, llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&) + 1553
8  swift                    0x00000001032f26a7 swift::SILInstructionVisitor<(anonymous namespace)::AdjointEmitter, void>::visit(swift::SILInstruction*) + 6871
9  swift                    0x00000001032c3dab (anonymous namespace)::Differentiation::run() + 7371
10 swift                    0x00000001033b66ab swift::SILPassManager::runModulePass(unsigned int) + 1083
11 swift                    0x00000001033b7184 swift::SILPassManager::execute() + 692
12 swift                    0x00000001029008fb swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 187
13 swift                    0x00000001033c0034 swift::runSILDiagnosticPasses(swift::SILModule&) + 132
14 swift                    0x00000001027884a1 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 10977
15 swift                    0x000000010278492d swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3021
16 swift                    0x00000001027366be main + 686
17 libdyld.dylib            0x00007fff7212ced9 start + 1
18 libdyld.dylib            0x000000000000000f start + 2381132087
@rxwei
Copy link
Member Author

rxwei commented Jan 21, 2019

#22024

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. swift for tensorflow
Projects
None yet
Development

No branches or pull requests

1 participant