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

remove tensor bound #297

Merged
merged 1 commit into from
Nov 7, 2022
Merged

remove tensor bound #297

merged 1 commit into from
Nov 7, 2022

Conversation

Dimev
Copy link
Contributor

@Dimev Dimev commented Nov 6, 2022

Solves #286

Also added a test in AddInto to see if that works in a longer network

Copy link
Owner

@coreylowman coreylowman left a comment

Choose a reason for hiding this comment

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

Awesome! Nice PR to review 😁

@coreylowman coreylowman merged commit bf60dbb into coreylowman:main Nov 7, 2022
@Dimev
Copy link
Contributor Author

Dimev commented Nov 7, 2022

Yep, nice and short
Does seem to panic on this code on line 77 due to unwrapping on a None, so this may not have been enough

type Model = (
    AddInto<(
        // phoneme a
        Linear<1, HIDDEN_SIZE>,
        
        // phoneme b         
        Linear<1, HIDDEN_SIZE>, 
        
        // noise
        Linear<1, HIDDEN_SIZE>, 
        
        // state
        Linear<STATE_SIZE, HIDDEN_SIZE>
    )>, 
    ReLU,
    SplitInto<(
        // state
        Linear<HIDDEN_SIZE, STATE_SIZE>,
        
        // next
        Linear<HIDDEN_SIZE, 1>,        

        // sample
        Linear<HIDDEN_SIZE, 1>
    )>
);

fn main() {
    // make rng
    let mut rng = StdRng::seed_from_u64(0);

    // make model
    let mut model = Model::default();
    
    // data TODO
    let x: Tensor1D<2> = Tensor1D::randn(&mut rng);
    let y: Tensor1D<8> = Tensor1D::randn(&mut rng);

    // gradient descent
    let mut sgd = Sgd::new(SgdConfig {
        lr: 0.01,
        momentum: Some(Momentum::Nesterov(0.9)),
        weight_decay: None,
    });

    // other idea:
    // generate a voice line
    // split on phonemes
    // train on one phoneme and that way you can still do batching

    // train
    for _ in 0..10 {
        // internal state
        let mut state = Tensor1D::<STATE_SIZE>::zeros().traced();

        for _ in 0..5 {

            // input
            let phoneme_a = Tensor1D::new([0.0]).traced();
            let phoneme_b = Tensor1D::new([0.0]).traced();
            let noise = Tensor1D::new([0.0]).traced();
            
            // forward
            let (new_state, next, sample) = model.forward((phoneme_a, phoneme_b, noise, state));

            // loss
            let loss = mse_loss(sample, Tensor1D::new([0.0]));

            // gradients, breaks here
            // thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /home/username/.cargo/git/checkouts/dfdx-318e6e5ad83eea79/3fc7be4/src/gradients.rs:273:14 
            let gradients = loss.backward();

            // update
            sgd.update(&mut model, gradients).expect("nn machine broke");
            
            // keep state
            state = new_state.traced();
        }
    }

    //println!("{:?}", model);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants