-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #18
base: master
Are you sure you want to change the base?
Conversation
return line.split(delim)[1] | ||
else: | ||
raise RuntimeError("Unable to find version string.") | ||
raise RuntimeError("Unable to find version string.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_version
refactored with the following changes:
- If else clause is always executed move code to same level as loop (
useless-else-on-loop
)
|
||
for _, model, _ in pkgutil.iter_modules([str(Path(__file__).parent / 'models')]): | ||
imported_module = importlib.import_module('.models.' + model, package=__name__) | ||
imported_module = importlib.import_module(f'.models.{model}', package=__name__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 13-13
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
data_path = Path(data_path) | ||
data_file = f'refseq/maps{max_seq_len}/refseq_{split}.lmdb' | ||
refseq_file = f'refseq/refseq.lmdb' | ||
refseq_file = 'refseq/refseq.lmdb' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function GeCMaskedReconstructionDataset.__init__
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
else: | ||
# 10% chance to keep current representation | ||
pass | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function GeCMaskedReconstructionDataset._apply_pseudobert_mask
refactored with the following changes:
- Remove redundant pass statement (
remove-redundant-pass
)
This removes the following comments ( why? ):
# 10% chance to keep current representation
else: | ||
# 10% chance to keep current token | ||
pass | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function ProteinMaskedLanguageModelingDataset._apply_bert_mask
refactored with the following changes:
- Remove redundant pass statement (
remove-redundant-pass
)
This removes the following comments ( why? ):
# 10% chance to keep current token
logger.error("Couldn't reach server at '{}' to download pretrained model " | ||
"configuration file.".format(config_file)) | ||
logger.error( | ||
f"Couldn't reach server at '{config_file}' to download pretrained model configuration file." | ||
) | ||
|
||
else: | ||
logger.error( | ||
"Model name '{}' was not found in model name list ({}). " | ||
"We assumed '{}' was a path or url but couldn't find any file " | ||
"associated to this path or url.".format( | ||
pretrained_model_name_or_path, | ||
', '.join(cls.pretrained_config_archive_map.keys()), | ||
config_file)) | ||
f"Model name '{pretrained_model_name_or_path}' was not found in model name list ({', '.join(cls.pretrained_config_archive_map.keys())}). We assumed '{config_file}' was a path or url but couldn't find any file associated to this path or url." | ||
) | ||
|
||
raise | ||
if resolved_config_file == config_file: | ||
logger.info("loading configuration file {}".format(config_file)) | ||
logger.info(f"loading configuration file {config_file}") | ||
else: | ||
logger.info("loading configuration file {} from cache at {}".format( | ||
config_file, resolved_config_file)) | ||
logger.info( | ||
f"loading configuration file {config_file} from cache at {resolved_config_file}" | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function BioConfig.from_pretrained
refactored with the following changes:
- Replace call to format with f-string [×4] (
use-fstring-for-formatting
)
"""Serializes this instance to a Python dictionary.""" | ||
output = copy.deepcopy(self.__dict__) | ||
return output | ||
return copy.deepcopy(self.__dict__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function BioConfig.to_dict
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
"Parameter config in `{}(config)` should be an instance of class " | ||
"`BioConfig`. To create a model from a pretrained model use " | ||
"`model = {}.from_pretrained(PRETRAINED_MODEL_NAME)`".format( | ||
self.__class__.__name__, self.__class__.__name__ | ||
)) | ||
f"Parameter config in `{self.__class__.__name__}(config)` should be an instance of class `BioConfig`. To create a model from a pretrained model use `model = {self.__class__.__name__}.from_pretrained(PRETRAINED_MODEL_NAME)`" | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function BioModel.__init__
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
p for n, p in param_optimizer if not any(nd in n for nd in no_decay) | ||
p | ||
for n, p in param_optimizer | ||
if all(nd not in n for nd in no_decay) | ||
], | ||
"weight_decay": 0.01, | ||
}, | ||
{ | ||
"params": [ | ||
p for n, p in param_optimizer if any(nd in n for nd in no_decay) | ||
p | ||
for n, p in param_optimizer | ||
if any(nd in n for nd in no_decay) | ||
], | ||
"weight_decay": 0.0, | ||
}, | ||
] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function BioModel.configure_optimizers
refactored with the following changes:
- Invert any/all to simplify comparisons (
invert-any-all
) - Use named expression to simplify assignment and conditional [×2] (
use-named-expression
)
@@ -1,5 +1,6 @@ | |||
"""PyTorch BERT model. """ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 12-15
refactored with the following changes:
- Use f-string instead of string concatenation [×4] (
use-fstring-for-concatenation
)
self.block_sizes = block_sizes | ||
else: | ||
self.block_sizes = [num_hidden_layers // 3] * 3 | ||
self.block_sizes = block_sizes or [num_hidden_layers // 3] * 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function BioFunnelConfig.__init__
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Simplify if expression by using or (
or-if-exp-identity
)
archive_file = cls.pretrained_model_archive_map[pretrained_model_name_or_path] | ||
return cls.pretrained_model_archive_map[pretrained_model_name_or_path] | ||
elif os.path.isdir(pretrained_model_name_or_path): | ||
archive_file = os.path.join(pretrained_model_name_or_path, WEIGHTS_NAME) | ||
return os.path.join(pretrained_model_name_or_path, WEIGHTS_NAME) | ||
else: | ||
archive_file = pretrained_model_name_or_path | ||
return archive_file | ||
return pretrained_model_name_or_path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function TAPEModelMixin._get_model
refactored with the following changes:
- Lift return into if (
lift-return-into-if
)
new_keys = {} | ||
for key in state_dict.keys(): | ||
new_keys[key] = cls._rewrite_module_name(key) | ||
new_keys = {key: cls._rewrite_module_name(key) for key in state_dict} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function TAPEModelMixin._rewrite_state_dict
refactored with the following changes:
- Convert for loop into dictionary comprehension (
dict-comprehension
) - Remove unnecessary call to keys() (
remove-dict-keys
)
any(s.startswith(cls.base_model_prefix) for s in state_dict.keys()): | ||
start_prefix = cls.base_model_prefix + '.' | ||
any(s.startswith(cls.base_model_prefix) for s in state_dict.keys()): | ||
start_prefix = f'{cls.base_model_prefix}.' | ||
if hasattr(model, cls.base_model_prefix) and \ | ||
not any(s.startswith(cls.base_model_prefix) for s in state_dict.keys()): | ||
not any(s.startswith(cls.base_model_prefix) for s in state_dict.keys()): | ||
model_to_load = getattr(model, cls.base_model_prefix) | ||
|
||
load(model_to_load, prefix=start_prefix) | ||
if len(missing_keys) > 0: | ||
if missing_keys: | ||
logger.info("Weights of {} not initialized from pretrained model: {}".format( | ||
model.__class__.__name__, missing_keys)) | ||
if len(unexpected_keys) > 0: | ||
if unexpected_keys: | ||
logger.info("Weights from pretrained model not used in {}: {}".format( | ||
model.__class__.__name__, unexpected_keys)) | ||
if len(error_msgs) > 0: | ||
if error_msgs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function TAPEModelMixin.from_pretrained
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Simplify sequence length comparison [×3] (
simplify-len-comparison
)
[T5Block(config, has_relative_attention_bias=bool(i == 0)) for i in range(config.num_layers)] | ||
[ | ||
T5Block(config, has_relative_attention_bias=i == 0) | ||
for i in range(config.num_layers) | ||
] | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function T5Stack.__init__
refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
outputs = sequence_logits | ||
|
||
return outputs | ||
return self.classify(sequence_output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SequenceToSequenceClassificationHead.forward
refactored with the following changes:
- Inline variable that is immediately returned [×2] (
inline-immediately-returned-variable
)
logits = self.classify(pooled_output) | ||
|
||
return logits | ||
return self.classify(pooled_output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SequenceClassificationHead.forward
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
loader = DataLoader( | ||
return DataLoader( | ||
dataset, | ||
num_workers=self.num_workers, | ||
collate_fn=dataset.collate_fn, | ||
batch_sampler=batch_sampler, | ||
) | ||
return loader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function BioDataModule._prep_loader
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
strands = torch.ones(shape[:-1], dtype=torch.long) | ||
if lengths: | ||
lengths = torch.ones(shape[:-1], dtype=torch.long) * lengths | ||
lengths *= torch.ones(shape[:-1], dtype=torch.long) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function TestGeCBertRaw.simpleForwardZeros
refactored with the following changes:
- Replace assignment with augmented assignment (
aug-assign
)
for batch in SubsetRandomSampler( | ||
list(BatchSampler(sorted_sampler, self.batch_size, self.drop_last))): | ||
yield batch | ||
yield from SubsetRandomSampler( | ||
list(BatchSampler(sorted_sampler, self.batch_size, self.drop_last)) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function BucketBatchSampler.__iter__
refactored with the following changes:
- Replace yield inside for loop with yield from (
yield-from
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.19%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
Branch
master
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
master
branch, then run:Help us improve this pull request!