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

Forward unification 1: add output type family, HasForward instances #477

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

mcwitt
Copy link
Collaborator

@mcwitt mcwitt commented Oct 22, 2020

Breaking up #459 into a series of more manageable chunks.

In this PR the goals are to:

  1. Update HasForward, replacing output type parameter b with a type family and removing fowardStoch. Stochastic vs. deterministic will now be determined by the associated type family for each instance, with types of the form Generator -> (a, Generator) stochastic.

  2. Add HasForwardProduct, HasForwardSum instances for products and sums. Eventually (not in this PR), we can dispatch to forwardProduct and forwardSum via a generic implementation of forward.

  3. Get everything to compile! This means updating all existing HasForward instances.

HasForward instance progress

  • Linear (but this is ugly; better to introduce intermediate type family?)
  • Normalization
  • Dropout
  • Sparse
  • Convolution
  • DataParallel (I'm not sure how to handle this one yet; got it to compile trivially, but it needs further updates)
  • Transformer
  • etc.

@mcwitt mcwitt mentioned this pull request Oct 22, 2020
@@ -34,9 +35,9 @@ dropoutForward ::
IO (Tensor device dtype shape)
dropoutForward Dropout {..} dropoutTrain = dropout dropoutProb dropoutTrain

instance HasForward Dropout (Tensor device dtype shape) (Tensor device dtype shape) where
instance HasForward Dropout (Tensor device dtype shape) where
type Output Dropout (Tensor device dtype shape) = Tensor device dtype shape
forward dropout input = unsafePerformIO $ dropoutForward dropout False input
Copy link
Member

@tscholak tscholak Oct 31, 2020

Choose a reason for hiding this comment

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

alright, I guess here we are blocked because there isn't a dropout implementation yet that supports generators

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, makes sense. My initial goal was just to get everything to compile, but makes sense that this is not very useful until we can augment the output type to make it stochastic.

@tscholak
Copy link
Member

@mcwitt This looks great!

Output
(TransformerLM numAttnLayers numHeads ffnDim paddingIdx numEmbeds embedDim dtype device)
(Tensor device 'D.Int64 '[batchSize, seqLen]) =
Tensor device dtype '[batchSize, seqLen, numEmbeds]
forward model input = unsafePerformIO $ transformerLM model False input
Copy link
Member

Choose a reason for hiding this comment

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

same here. I hope we can get a dropout soon that takes a generator as argument. otherwise, we can't train these models with dropout.

Copy link
Member

Choose a reason for hiding this comment

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

this still isn't resolved :/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, too bad. When I find some time I'm hoping to try to reproduce the test failure in Junji's PR and see if I can make any progress..

@tscholak
Copy link
Member

tscholak commented Jul 7, 2021

hey, do you want to revisit this for Torch.GraduallyTyped?
it would go here: https://github.com/hasktorch/hasktorch/blob/master/experimental/gradually-typed/src/Torch/GraduallyTyped/NN/Class.hs#L45

@mcwitt
Copy link
Collaborator Author

mcwitt commented Jul 9, 2021

hey, do you want to revisit this for Torch.GraduallyTyped?

@tscholak yep, I'm pretty excited to try this out!

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.

None yet

2 participants