Skip to content

feature/gmodels: Allow generic In/Out on models#248

Merged
gbaydin merged 18 commits intodevfrom
feature/gmodels
Jul 22, 2021
Merged

feature/gmodels: Allow generic In/Out on models#248
gbaydin merged 18 commits intodevfrom
feature/gmodels

Conversation

@dsyme
Copy link
Copy Markdown
Collaborator

@dsyme dsyme commented Nov 19, 2020

Generalises models to allow a generic In/Out, as used in transformer architectures

type Model<'In, 'Out>
type Model = Model<Tensor, Tensor>

There are other ways to do this but this seems as good as any.

@codecov
Copy link
Copy Markdown

codecov bot commented Nov 19, 2020

Codecov Report

Merging #248 (a9f9182) into dev (0ed6f78) will decrease coverage by 0.75%.
The diff coverage is 76.19%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #248      +/-   ##
==========================================
- Coverage   66.01%   65.26%   -0.75%     
==========================================
  Files           5       29      +24     
  Lines        2401     6664    +4263     
  Branches      641     1573     +932     
==========================================
+ Hits         1585     4349    +2764     
- Misses        520     1472     +952     
- Partials      296      843     +547     
Impacted Files Coverage Δ
src/DiffSharp.Core/Model.fs 73.05% <76.19%> (ø)
src/DiffSharp.Data/Image.fs 76.92% <0.00%> (-0.85%) ⬇️
src/DiffSharp.Data/Data.fs 69.41% <0.00%> (-0.65%) ⬇️
src/DiffSharp.Data/Plot.fs 0.00% <0.00%> (ø)
src/DiffSharp.Core/RawTensor.fs 84.97% <0.00%> (ø)
src/DiffSharp.Core/Model.Dropout.fs 75.00% <0.00%> (ø)
src/DiffSharp.Core/Dtype.fs 71.74% <0.00%> (ø)
src/DiffSharp.Core/Tensor.fs 62.97% <0.00%> (ø)
src/DiffSharp.Core/Model.ConvTranspose.fs 71.88% <0.00%> (ø)
src/DiffSharp.Core/Extensions.fs 54.55% <0.00%> (ø)
... and 20 more

@dsyme dsyme changed the title Feature: Allow generic In/Out on models feature/gmodels: Allow generic In/Out on models Nov 28, 2020
@dsyme
Copy link
Copy Markdown
Collaborator Author

dsyme commented Mar 29, 2021

@gbaydin I think this can be merged, or you can take the change and apply it into your own work on transformers?

It raises separate questions of generalizing differentiable objects to beyond tensors but I think we can deal with those later, this seems like a reasonable minimal start?

@gbaydin
Copy link
Copy Markdown
Member

gbaydin commented Mar 30, 2021

Actually this is indeed very relevant for the type of things I'm working on. For example in recurrent models I had to think about a design to pass and return hidden state tensors in addition to the input and return values of .forward. Thanks for pinging, I'm going to have a close look and merge.

@gbaydin
Copy link
Copy Markdown
Member

gbaydin commented Jul 22, 2021

@dsyme I added a couple of fixes.

I think the most important one was that Model<'In, 'Out>.clone was returning Model<Tensor, Tensor> which I fixed to return Model<'In, 'Out>.

I also moved a few things that were not involving <'In, 'Out> to BaseModel.

I'm really happy about this PR in general. I think this is quite nice and powerful! For example, we can do things like:

  • Model<string, string> for machine translation between languages
  • Model<unit,Tensor> for some generative models etc.

Also after reading through all <'In, 'Out>s this reminds me of https://www.in-n-out.com/ :)

@gbaydin gbaydin merged commit 59282fc into dev Jul 22, 2021
@dsyme
Copy link
Copy Markdown
Collaborator Author

dsyme commented Jul 22, 2021

This is great, thanks for refining it!

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