Skip to content

Conversation

@SourceryAI
Copy link

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 master branch, then run:

git fetch https://github.com/sourcery-ai-bot/autogluon master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Copy link
Author

@SourceryAI SourceryAI left a 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.

Comment on lines -27 to +31
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")
Copy link
Author

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:

Comment on lines +15 to +17



Copy link
Author

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:

Comment on lines +74 to +76



Copy link
Author

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:

Comment on lines -282 to +292
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)
Copy link
Author

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:

Comment on lines -300 to +309
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}'
Copy link
Author

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:

Comment on lines -12 to +18
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)
}

Copy link
Author

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:

else:
if SPLITTER in k:
continue
elif SPLITTER not in k:
Copy link
Author

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:

Comment on lines -78 to -84
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})
Copy link
Author

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:

Comment on lines -107 to +105
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}'
Copy link
Author

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:

Comment on lines -137 to +133
default = dict()
default = {}
Copy link
Author

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:

Comment on lines +262 to +264



Copy link
Author

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:

Comment on lines -25 to +27
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}'
Copy link
Author

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:

"""
default = self._default if self._default else self.hp.default_value
return default
return self._default or self.hp.default_value
Copy link
Author

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:

Comment on lines -132 to +134
def kwspaces(cls):
def kwspaces(self):
""" OrderedDict representation of this search space.
"""
return cls.__init__.kwspaces
return self.__init__.kwspaces
Copy link
Author

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:

Comment on lines -166 to +165
for elem in self.data:
yield elem
yield from self.data
Copy link
Author

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)

Comment on lines -490 to +484
elif not prefix == '':
new_parameter.name = "{}{}{}".format(prefix, SPLITTER, new_parameter.name)
elif prefix != '':
new_parameter.name = f"{prefix}{SPLITTER}{new_parameter.name}"
Copy link
Author

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:

Comment on lines -500 to +493
if hp.name.startswith('{}'.format(k)):
if hp.name.startswith(f'{k}'):
Copy link
Author

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:

@classmethod
def set_id(cls, taskid):
logger.info('Setting TASK ID: {}'.format(taskid))
logger.info(f'Setting TASK ID: {taskid}')
Copy link
Author

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:

Comment on lines -48 to +54
' (' + '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}, '
Copy link
Author

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:

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')
Copy link
Author

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:

Comment on lines -100 to -109
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
Copy link
Author

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:

Comment on lines -115 to +181
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
)
Copy link
Author

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:

if not multiplier:
return repeats
return int(math.ceil(multiplier * repeats))
return int(math.ceil(multiplier * repeats)) if multiplier else repeats
Copy link
Author

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:

Comment on lines -101 to +99
return '{} (beta={})'.format(self.__class__.__name__, self._beta)
return f'{self.__class__.__name__} (beta={self._beta})'
Copy link
Author

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:

if isinstance(searcher, str):
if search_options is None:
search_options = dict()
search_options = {}
Copy link
Author

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:

Comment on lines -443 to +449
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
Copy link
Author

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:

Comment on lines -569 to +571
"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}')
Copy link
Author

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:

Comment on lines -612 to +610
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']}"

Copy link
Author

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:

Comment on lines -627 to +623
reprstr = self.__class__.__name__ + '(' + \
'terminator: ' + str(self.terminator)
return reprstr
return f'{self.__class__.__name__}(terminator: {str(self.terminator)}'
Copy link
Author

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:

self._min_t = grace_period
# Maps str(task_id) -> bracket_id
self._task_info = dict()
self._task_info = {}
Copy link
Author

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:

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.

1 participant