Skip to content

Refactor data structures to reduce memory usage#142

Merged
copybara-service[bot] merged 3 commits intogoogle:devfrom
ufownl:refactor/data_structures
Apr 10, 2024
Merged

Refactor data structures to reduce memory usage#142
copybara-service[bot] merged 3 commits intogoogle:devfrom
ufownl:refactor/data_structures

Conversation

@ufownl
Copy link
Copy Markdown
Contributor

@ufownl ufownl commented Apr 10, 2024

This PR moves the Gemma attention weights and Griffin weights into a union to share memory and reduces the additional overhead when not using the Griffin model.

Copy link
Copy Markdown
Member

@jan-wassenberg jan-wassenberg left a comment

Choose a reason for hiding this comment

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

Nice, thanks for resolving this TODO :) Some suggestions:

Comment thread gemma/gemma.cc Outdated
static constexpr size_t kGatingEinsumWSize = 2 * kFFHiddenDim * kModelDim;
static constexpr size_t kConv1dWidth = TConfig::kConv1dWidth;
static constexpr bool kFFBiases = TConfig::kFFBiases;
static constexpr size_t kAOBiaseDim =
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Typo (extra e), maybe instead kAttnBiasDim?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oops, my bad.

Comment thread gemma/gemma.cc Outdated
};

struct {
ArrayT<float, kGriffinDim * kGriffinDim> griffin_linear_x_w;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Consider naming the struct member griffin, so we can remove the griffin_ prefix from its names?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree, your solution should be better.

Comment thread gemma/gemma.cc Outdated
static constexpr size_t kGatingEinsumWSize = TLayer::kGatingEinsumWSize;
static constexpr size_t kConv1dWidth = TLayer::kConv1dWidth;
static constexpr bool kFFBiases = TLayer::kFFBiases;
static constexpr size_t kAOBiaseDim = TLayer::kAOBiaseDim;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here also rename?

Copy link
Copy Markdown
Member

@jan-wassenberg jan-wassenberg left a comment

Choose a reason for hiding this comment

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

Nice, thanks for making the change :)

@jan-wassenberg jan-wassenberg added the copybara-import Trigger Copybara for merging pull requests label Apr 10, 2024
@copybara-service copybara-service Bot merged commit 342e998 into google:dev Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copybara-import Trigger Copybara for merging pull requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants