Skip to content

nlp_seq to linen port#609

Merged
copybara-service[bot] merged 1 commit into
masterfrom
nlp_seq_linen
Nov 12, 2020
Merged

nlp_seq to linen port#609
copybara-service[bot] merged 1 commit into
masterfrom
nlp_seq_linen

Conversation

@bohnetbd
Copy link
Copy Markdown
Contributor

@bohnetbd bohnetbd commented Nov 9, 2020

I carried out the changes to port the example to linen.

@google-cla google-cla Bot added the cla: yes label Nov 9, 2020
@codecov-io
Copy link
Copy Markdown

codecov-io commented Nov 9, 2020

Codecov Report

Merging #609 (81ce95f) into master (b8befd4) will decrease coverage by 1.13%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #609      +/-   ##
==========================================
- Coverage   80.44%   79.31%   -1.14%     
==========================================
  Files          55       55              
  Lines        4199     4259      +60     
==========================================
  Hits         3378     3378              
- Misses        821      881      +60     
Impacted Files Coverage Δ
flax/testing/benchmark.py 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b8befd4...81ce95f. Read the comment docs.

@bohnetbd bohnetbd self-assigned this Nov 9, 2020
@bohnetbd bohnetbd closed this Nov 9, 2020
@bohnetbd bohnetbd deleted the nlp_seq_linen branch November 9, 2020 11:02
Copy link
Copy Markdown
Contributor

@andsteing andsteing left a comment

Choose a reason for hiding this comment

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

Thanks - that will make for the largest tickbox in #568 :-)

Added some initial comments.

Comment thread examples/nlp_seq/train.py
This script trains a Transformer on the Universal dependency dataset.
"""

import tensorflow as tf
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

https://www.python.org/dev/peps/pep-0008/#imports

Imports should be grouped in the following order:

1. Standard library imports.
2. Related third party imports.
3. Local application/library specific imports.
You should put a blank line between each group of imports.

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.

Thanks. Changed.

# Do nothing in predict mode, as then the sequence length is 1.
return x

from flax import linen as nn
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

https://www.python.org/dev/peps/pep-0008/#imports

Imports should be grouped in the following order:

1. Standard library imports.
2. Related third party imports.
3. Local application/library specific imports.
You should put a blank line between each group of imports.

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.

Thanks! Changed tool

dtype=cfg.dtype,
kernel_init=cfg.kernel_init,
bias_init=cfg.bias_init)(inputs)
x = nn.relu(x)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

gelu -> relu : is this intentional ?

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.

no not intentional. changed it back.

@nn.compact
def __call__(self,
inputs,
inputs_positions=None):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(Here and elsewhere)

Can we make all arguments to __call__() kw-only?
Ideally, we would also add a type annotation.

See also #231 (comment)

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.

done. left type annotations out (for now?)

train=True,
dropout_rate=0.3,
attention_dropout_rate=0.3):
train=False,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we make the additional arguments kw-only and remove the default from the train argument?

See also #231 (comment)

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.

done.

dropout_rate=0.3,
attention_dropout_rate=0.3):
train=False,
dropout_rate=0.3):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is this not a setting in TransformerConfig ?

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.

now taken from TransformerConfig. Thanks!

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.

use dropout from config.

@nn.compact
def __call__(self,
inputs,
encoder_mask=None,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we make all arguments to __call__() kw-only?

See also #231 (comment)

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.

done.

@andsteing andsteing mentioned this pull request Nov 9, 2020
@bohnetbd bohnetbd restored the nlp_seq_linen branch November 9, 2020 14:00
@bohnetbd bohnetbd reopened this Nov 9, 2020
Comment thread examples/nlp_seq/train.py
lambda x: x / eval_denominator, # pylint: disable=cell-var-from-loop
eval_metrics_sums)

# Calculate (clipped) perplexity after averaging log-perplexities:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why is this removed?

@copybara-service copybara-service Bot merged commit f51707d into master Nov 12, 2020
@copybara-service copybara-service Bot deleted the nlp_seq_linen branch November 12, 2020 07:46
bohnetbd added a commit that referenced this pull request Nov 13, 2020
Changes due to review of andsteing no resolved PR #609
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.31%. Comparing base (b8befd4) to head (81ce95f).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #609      +/-   ##
==========================================
- Coverage   80.44%   79.31%   -1.14%     
==========================================
  Files          55       55              
  Lines        4199     4259      +60     
==========================================
  Hits         3378     3378              
- Misses        821      881      +60     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants