-
Notifications
You must be signed in to change notification settings - Fork 1
Sourcery Starbot ⭐ refactored testvinder/autogluon #1
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
base: master
Are you sure you want to change the base?
Conversation
SourceryAI
left a comment
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.
Sourcery timed out performing refactorings.
Due to GitHub API limits, only the first 60 comments can be shown.
| print('-- Building version ' + version) | ||
| print(f'-- Building version {version}') | ||
| version_path = os.path.join(cwd, 'autogluon', 'version.py') | ||
| with open(version_path, 'w') as f: | ||
| f.write('"""This is autogluon version file."""\n') | ||
| f.write("__version__ = '{}'\n".format(version)) | ||
| f.write(f"__version__ = '{version}'\n") |
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 create_version_file refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Replace call to format with f-string (
use-fstring-for-formatting)
|
|
||
|
|
||
|
|
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 enas_unit refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
|
|
||
|
|
||
|
|
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 enas_net refactored with the following changes:
- Remove unnecessary call to keys() (
remove-dict-keys)
| if hasattr(op, 'evaluate_latency'): | ||
| x = op.evaluate_latency(x) | ||
| else: | ||
| x = op(x) | ||
| x = op.evaluate_latency(x) if hasattr(op, 'evaluate_latency') else op(x) |
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 ENAS_Sequential.evaluate_latency refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| reprstr = self.__class__.__name__ + '(' | ||
| reprstr = f'{self.__class__.__name__}(' | ||
| for i, op in self._modules.items(): | ||
| reprstr += '\n\t{}: {}'.format(i, op) | ||
| reprstr += f'\n\t{i}: {op}' |
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 ENAS_Sequential.__repr__ refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Replace call to format with f-string (
use-fstring-for-formatting)
| train_args = {} | ||
| base_lr = 0.1 * batch_size / 256 | ||
| lr_scheduler = gcv.utils.LRScheduler('cosine', base_lr=base_lr, target_lr=0.0001, | ||
| nepochs=epochs, iters_per_epoch=iters_per_epoch) | ||
| optimizer_params = {'wd': 1e-4, 'momentum': 0.9, 'lr_scheduler': lr_scheduler} | ||
| train_args['trainer'] = gluon.Trainer(net.collect_params(), 'sgd', optimizer_params) | ||
| train_args = { | ||
| 'trainer': gluon.Trainer(net.collect_params(), 'sgd', optimizer_params) | ||
| } | ||
|
|
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 init_default_train_args refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block) - Merge dictionary assignment with declaration (
merge-dict-assign)
| else: | ||
| if SPLITTER in k: | ||
| continue | ||
| elif SPLITTER not in k: |
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 sample_config refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif) - Lift code into else after jump in control flow (
reintroduce-else) - Remove redundant continue statement (
remove-redundant-continue)
| if isinstance(v, (NestedSpace)): | ||
| if isinstance(v, (NestedSpace)) or not isinstance(v, Space): | ||
| self.args.update({k: v}) | ||
| elif isinstance(v, Space): | ||
| else: | ||
| hp = v.get_hp(name=k) | ||
| self.args.update({k: hp.default_value}) | ||
| else: | ||
| self.args.update({k: v}) |
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 _autogluon_method.update refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks) - Remove redundant conditional (
remove-redundant-if)
| kw_spaces['{}{}choice'.format(k, SPLITTER)] = v | ||
| kw_spaces[f'{k}{SPLITTER}choice'] = v | ||
| for sub_k, sub_v in v.kwspaces.items(): | ||
| new_k = '{}{}{}'.format(k, SPLITTER, sub_k) | ||
| new_k = f'{k}{SPLITTER}{sub_k}' |
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 _autogluon_method.kwspaces refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting)
| default = dict() | ||
| default = {} |
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 args refactored with the following changes:
- Replace dict() with {} (
dict-literal)
|
|
||
|
|
||
|
|
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 obj refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| reprstr += ': lower={}, upper={}'.format(self.lower, self.upper) | ||
| reprstr += f': lower={self.lower}, upper={self.upper}' | ||
| if hasattr(self, 'value'): | ||
| reprstr += ': value={}'.format(self.value) | ||
| reprstr += f': value={self.value}' |
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 SimpleSpace.__repr__ refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting)
| """ | ||
| default = self._default if self._default else self.hp.default_value | ||
| return default | ||
| return self._default or self.hp.default_value |
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 SimpleSpace.default refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable) - Simplify if expression by using or (
or-if-exp-identity)
| def kwspaces(cls): | ||
| def kwspaces(self): | ||
| """ OrderedDict representation of this search space. | ||
| """ | ||
| return cls.__init__.kwspaces | ||
| return self.__init__.kwspaces |
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 AutoGluonObject.kwspaces refactored with the following changes:
- The first argument to instance methods should be
self(instance-method-first-arg-name)
| for elem in self.data: | ||
| yield elem | ||
| yield from self.data |
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 List.__iter__ refactored with the following changes:
- Replace yield inside for loop with yield from (
yield-from)
| elif not prefix == '': | ||
| new_parameter.name = "{}{}{}".format(prefix, SPLITTER, new_parameter.name) | ||
| elif prefix != '': | ||
| new_parameter.name = f"{prefix}{SPLITTER}{new_parameter.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 _add_cs refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan) - Replace call to format with f-string (
use-fstring-for-formatting)
| if hp.name.startswith('{}'.format(k)): | ||
| if hp.name.startswith(f'{k}'): |
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 _rm_hp refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| @classmethod | ||
| def set_id(cls, taskid): | ||
| logger.info('Setting TASK ID: {}'.format(taskid)) | ||
| logger.info(f'Setting TASK ID: {taskid}') |
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 Task.set_id refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| ' (' + 'task_id: ' + str(self.task_id) + \ | ||
| ',\n\tfn: ' + str(self.fn) + \ | ||
| ',\n\targs: {' | ||
| ' (' + 'task_id: ' + str(self.task_id) + \ | ||
| ',\n\tfn: ' + str(self.fn) + \ | ||
| ',\n\targs: {' | ||
| for k, v in self.args.items(): | ||
| data = str(v) | ||
| info = (data[:100] + '..') if len(data) > 100 else data | ||
| reprstr += '{}'.format(k) + ': ' + info + ', ' | ||
| info = f'{data[:100]}..' if len(data) > 100 else data | ||
| reprstr += f'{k}: {info}, ' |
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 Task.__repr__ refactored with the following changes:
- Use f-string instead of string concatenation [×4] (
use-fstring-for-concatenation) - Replace call to format with f-string (
use-fstring-for-formatting)
| file_name = '{name}-{short_hash}'.format(name=name, short_hash=short_hash(name)) | ||
| root = os.path.expanduser(root) | ||
| file_path = os.path.join(root, file_name+'.params') | ||
| file_path = os.path.join(root, f'{file_name}.params') |
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_model_file refactored with the following changes:
- Use f-string instead of string concatenation [×3] (
use-fstring-for-concatenation) - Replace call to format with f-string (
use-fstring-for-formatting)
| blocks_args = [ | ||
| EasyDict(kernel=3, num_repeat=1, channels=16, expand_ratio=1, stride=1, se_ratio=0.25, in_channels=32), | ||
| EasyDict(kernel=3, num_repeat=2, channels=24, expand_ratio=6, stride=2, se_ratio=0.25, in_channels=16), | ||
| EasyDict(kernel=5, num_repeat=2, channels=40, expand_ratio=6, stride=2, se_ratio=0.25, in_channels=24), | ||
| EasyDict(kernel=3, num_repeat=3, channels=80, expand_ratio=6, stride=2, se_ratio=0.25, in_channels=40), | ||
| EasyDict(kernel=5, num_repeat=3, channels=112, expand_ratio=6, stride=1, se_ratio=0.25, in_channels=80), | ||
| EasyDict(kernel=5, num_repeat=4, channels=192, expand_ratio=6, stride=2, se_ratio=0.25, in_channels=112), | ||
| EasyDict(kernel=3, num_repeat=1, channels=320, expand_ratio=6, stride=1, se_ratio=0.25, in_channels=192), | ||
| return [ | ||
| EasyDict( | ||
| kernel=3, | ||
| num_repeat=1, | ||
| channels=16, | ||
| expand_ratio=1, | ||
| stride=1, | ||
| se_ratio=0.25, | ||
| in_channels=32, | ||
| ), | ||
| EasyDict( | ||
| kernel=3, | ||
| num_repeat=2, | ||
| channels=24, | ||
| expand_ratio=6, | ||
| stride=2, | ||
| se_ratio=0.25, | ||
| in_channels=16, | ||
| ), | ||
| EasyDict( | ||
| kernel=5, | ||
| num_repeat=2, | ||
| channels=40, | ||
| expand_ratio=6, | ||
| stride=2, | ||
| se_ratio=0.25, | ||
| in_channels=24, | ||
| ), | ||
| EasyDict( | ||
| kernel=3, | ||
| num_repeat=3, | ||
| channels=80, | ||
| expand_ratio=6, | ||
| stride=2, | ||
| se_ratio=0.25, | ||
| in_channels=40, | ||
| ), | ||
| EasyDict( | ||
| kernel=5, | ||
| num_repeat=3, | ||
| channels=112, | ||
| expand_ratio=6, | ||
| stride=1, | ||
| se_ratio=0.25, | ||
| in_channels=80, | ||
| ), | ||
| EasyDict( | ||
| kernel=5, | ||
| num_repeat=4, | ||
| channels=192, | ||
| expand_ratio=6, | ||
| stride=2, | ||
| se_ratio=0.25, | ||
| in_channels=112, | ||
| ), | ||
| EasyDict( | ||
| kernel=3, | ||
| num_repeat=1, | ||
| channels=320, | ||
| expand_ratio=6, | ||
| stride=1, | ||
| se_ratio=0.25, | ||
| in_channels=192, | ||
| ), | ||
| ] | ||
| return blocks_args |
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_efficientnet_blockargs refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| model = EfficientNet(blocks_args, dropout_rate, num_classes, width_coefficient, | ||
| depth_coefficient, depth_divisor, min_depth, drop_connect_rate, | ||
| input_size, **kwargs) | ||
| return model | ||
| return EfficientNet( | ||
| blocks_args, | ||
| dropout_rate, | ||
| num_classes, | ||
| width_coefficient, | ||
| depth_coefficient, | ||
| depth_divisor, | ||
| min_depth, | ||
| drop_connect_rate, | ||
| input_size, | ||
| **kwargs | ||
| ) |
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_efficientnet refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| if not multiplier: | ||
| return repeats | ||
| return int(math.ceil(multiplier * repeats)) | ||
| return int(math.ceil(multiplier * repeats)) if multiplier else repeats |
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 round_repeats refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp) - Swap if/else branches of if expression to remove negation (
swap-if-expression)
| return '{} (beta={})'.format(self.__class__.__name__, self._beta) | ||
| return f'{self.__class__.__name__} (beta={self._beta})' |
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 Swish.__repr__ refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| if isinstance(searcher, str): | ||
| if search_options is None: | ||
| search_options = dict() | ||
| search_options = {} |
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 FIFOScheduler.__init__ refactored with the following changes:
- Replace dict() with {} (
dict-literal) - Simplify if expression by using or (
or-if-exp-identity) - Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| key = 'count_at_{}'.format(k) | ||
| key = f'count_at_{k}' | ||
| reported_result[key] = v | ||
| dataset_size = self.searcher.dataset_size() | ||
| if dataset_size > 0: | ||
| reported_result['searcher_data_size'] = dataset_size | ||
| for k, v in self.searcher.cumulative_profile_record().items(): | ||
| reported_result['searcher_profile_' + k] = v | ||
| reported_result[f'searcher_profile_{k}'] = v | ||
| for k, v in self.searcher.model_parameters().items(): | ||
| reported_result['searcher_params_' + k] = v | ||
| reported_result[f'searcher_params_{k}'] = v |
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 HyperbandScheduler._run_reporter refactored with the following changes:
- Replace call to format with f-string [×4] (
use-fstring-for-formatting) - Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation) - Use previously assigned local variable (
use-assigned-variable)
| "load_state_dict must only be called as part of scheduler construction" | ||
| "load_state_dict must only be called as part of scheduler construction" | ||
| super().load_state_dict(state_dict) | ||
| # Note: _running_tasks is empty from __init__, it is not recreated, | ||
| # since running tasks are not part of the checkpoint | ||
| self.terminator = pickle.loads(state_dict['terminator']) | ||
| logger.info('Loading Terminator State {}'.format(self.terminator)) | ||
| logger.info(f'Loading Terminator State {self.terminator}') |
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 HyperbandScheduler.load_state_dict refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| msg = "config_id {}: Promotion from {} to {}".format( | ||
| config_id, extra_kwargs['resume_from'], | ||
| extra_kwargs['milestone']) | ||
| msg = f"config_id {config_id}: Promotion from {extra_kwargs['resume_from']} to {extra_kwargs['milestone']}" | ||
|
|
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 HyperbandScheduler._promote_config refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| reprstr = self.__class__.__name__ + '(' + \ | ||
| 'terminator: ' + str(self.terminator) | ||
| return reprstr | ||
| return f'{self.__class__.__name__}(terminator: {str(self.terminator)}' |
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 HyperbandScheduler.__repr__ refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable) - Use f-string instead of string concatenation [×3] (
use-fstring-for-concatenation)
| self._min_t = grace_period | ||
| # Maps str(task_id) -> bracket_id | ||
| self._task_info = dict() | ||
| self._task_info = {} |
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 HyperbandPromotion_Manager.__init__ refactored with the following changes:
- Replace dict() with {} (
dict-literal)
Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨
Here's your pull request refactoring your most popular Python repo.
If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.
Review changes via command line
To manually merge these changes, make sure you're on the
masterbranch, then run: