Skip to content

Sourcery refactored main branch - #1

Open
sourcery-ai[bot] wants to merge 1 commit into
mainfrom
sourcery/main
Open

Sourcery refactored main branch#1
sourcery-ai[bot] wants to merge 1 commit into
mainfrom
sourcery/main

Conversation

@sourcery-ai

@sourcery-ai sourcery-ai Bot commented Nov 4, 2023

Copy link
Copy Markdown

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

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai
sourcery-ai Bot requested a review from ayaz345 November 4, 2023 15:51

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Due to GitHub API limits, only the first 60 comments can be shown.

Comment thread demo.py
)
args = parser.parse_args()
return args
return parser.parse_args()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function parse_args refactored with the following changes:

Comment thread demo.py
Comment on lines -65 to +64
model = model_cls.from_config(model_config).to('cuda:{}'.format(args.gpu_id))
model = model_cls.from_config(model_config).to(f'cuda:{args.gpu_id}')

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Lines 65-76 refactored with the following changes:

Comment thread demo_v2.py
)
args = parser.parse_args()
return args
return parser.parse_args()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function parse_args refactored with the following changes:

Comment thread demo_v2.py
Comment on lines -58 to +57
device = 'cuda:{}'.format(args.gpu_id)
device = f'cuda:{args.gpu_id}'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Lines 58-58 refactored with the following changes:

Comment thread demo_v2.py
Comment on lines -89 to +88
substrings = [match for match in matches]

return substrings
return list(matches)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function extract_substrings refactored with the following changes:

Comment thread minigpt4/common/config.py
return opts

return [(opt + "=" + value) for opt, value in zip(opts[0::2], opts[1::2])]
return [f"{opt}={value}" for opt, value in zip(opts[::2], opts[1::2])]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Config._convert_to_dot_list refactored with the following changes:

Comment thread minigpt4/common/config.py
# description + key-value pair string for each argument
help_msg = str(self.description)
return help_msg + ", available arguments: " + self.format_arguments()
return f"{help_msg}, available arguments: {self.format_arguments()}"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function ConfigValidator.format_help refactored with the following changes:

Comment thread minigpt4/common/config.py
Comment on lines -328 to +335
help="Learning rate scheduler to use, from {}".format(lr_scheds_choices),
help=f"Learning rate scheduler to use, from {lr_scheds_choices}",
)
task_choices = registry.list_tasks()
validator.add_argument(
"task",
type=str,
choices=task_choices,
help="Task to use, from {}".format(task_choices),
help=f"Task to use, from {task_choices}",

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function create_runner_config_validator refactored with the following changes:

if not dist.is_initialized():
return False
return True
return False if not dist.is_available() else bool(dist.is_initialized())

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function is_dist_avail_and_initialized refactored with the following changes:

Comment on lines -42 to +38
if not is_dist_avail_and_initialized():
return 1
return dist.get_world_size()
return 1 if not is_dist_avail_and_initialized() else dist.get_world_size()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function get_world_size refactored with the following changes:

Comment on lines -48 to +42
if not is_dist_avail_and_initialized():
return 0
return dist.get_rank()
return 0 if not is_dist_avail_and_initialized() else dist.get_rank()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function get_rank refactored with the following changes:

Comment on lines -78 to +70
"| distributed init (rank {}, world {}): {}".format(
args.rank, args.world_size, args.dist_url
),
f"| distributed init (rank {args.rank}, world {args.world_size}): {args.dist_url}",

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function init_distributed_mode refactored with the following changes:

Comment on lines -39 to +42
[conv.append_message(
conv.roles[0], '<Img><ImageHere></Img> {}'.format(text)) for conv, text in zip(convs, texts)]
[
conv.append_message(conv.roles[0], f'<Img><ImageHere></Img> {text}')
for conv, text in zip(convs, texts)
]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function prepare_texts refactored with the following changes:

Comment on lines -75 to +77
iou = intersection_area / union_area
return iou
return intersection_area / union_area

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function computeIoU refactored with the following changes:

Comment thread minigpt4/common/logger.py
return self.__dict__[attr]
raise AttributeError(
"'{}' object has no attribute '{}'".format(type(self).__name__, attr)
f"'{type(self).__name__}' object has no attribute '{attr}'"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function MetricLogger.__getattr__ refactored with the following changes:

Comment thread minigpt4/common/utils.py
Comment on lines -423 to +415
size_in_mb = os.path.getsize(filename) / float(1024**2)
return size_in_mb
return os.path.getsize(filename) / float(1024**2)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function get_file_size refactored with the following changes:

self.qqa = {}
self.imgToQA = {}
if not annotation_file == None and not question_file == None:
if annotation_file is not None and question_file is not None:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function VQA.__init__ refactored with the following changes:

  • Simplify logical expression using De Morgan identities [×2] (de-morgan)
  • Use x is None rather than x == None [×2] (none-compare)

"""
for key, value in self.datset["info"].items():
print("%s: %s" % (key, value))
print(f"{key}: {value}")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function VQA.info refactored with the following changes:

Comment on lines -94 to +100
if not len(imgIds) == 0:
if len(imgIds) != 0:
anns = sum(
[self.imgToQA[imgId] for imgId in imgIds if imgId in self.imgToQA],
(
self.imgToQA[imgId]
for imgId in imgIds
if imgId in self.imgToQA
),

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function VQA.getQuesIds refactored with the following changes:

Comment on lines -129 to +133
if not len(quesIds) == 0:
anns = sum(
[self.qa[quesId] for quesId in quesIds if quesId in self.qa], []
)
if len(quesIds) != 0:
anns = sum((self.qa[quesId] for quesId in quesIds if quesId in self.qa), [])

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function VQA.getImgIds refactored with the following changes:

for ann in anns:
quesId = ann["question_id"]
print("Question: %s" % (self.qqa[quesId]["question"]))
print(f'Question: {self.qqa[quesId]["question"]}')

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function VQA.showQA refactored with the following changes:

Comment on lines -194 to +195
if quesIds == None:
quesIds = [quesId for quesId in self.params["question_id"]]
if quesIds is None:
quesIds = list(self.params["question_id"])

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function VQAEval.evaluate refactored with the following changes:

Comment on lines -252 to +255
if (p + " " in inText or " " + p in inText) or (
re.search(self.commaStrip, inText) != None
if (
f"{p} " in inText
or f" {p}" in inText
or re.search(self.commaStrip, inText) != None

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function VQAEval.processPunctuation refactored with the following changes:

Comment on lines -268 to +273
else:
pass
for wordId, word in enumerate(outText):
if word in self.contractions:
outText[wordId] = self.contractions[word]
outText = " ".join(outText)
return outText
return " ".join(outText)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function VQAEval.processDigitArticle refactored with the following changes:

Comment on lines -70 to +71
if quesIds == None:
quesIds = [quesId for quesId in self.params['question_id']]
if quesIds is None:
quesIds = list(self.params['question_id'])

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function VQAEval.evaluate refactored with the following changes:

Comment on lines -230 to +222
msg = "Received."

return msg
return "Received."

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Chat.upload_img refactored with the following changes:

Comment on lines -156 to +162
), "Do not support multiple {} datasets.".format(split_name)
), f"Do not support multiple {split_name} datasets."
datasets[split_name] = datasets[split_name][0]
else:
iterable_datasets, map_datasets = [], []
for dataset in datasets[split_name]:
if isinstance(dataset, wds.DataPipeline):
logging.info(
"Dataset {} is IterableDataset, can't be concatenated.".format(
dataset
)
)
logging.info(f"Dataset {dataset} is IterableDataset, can't be concatenated.")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function concat_datasets refactored with the following changes:

else:
cfg = load_dataset_config(cfg_path)

cfg = None if cfg_path is None else load_dataset_config(cfg_path)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function load_dataset refactored with the following changes:

datasets = self.build() # dataset['train'/'val'/'test']

return datasets
return self.build()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function BaseDatasetBuilder.build_datasets refactored with the following changes:

This removes the following comments ( why? ):

# dataset['train'/'val'/'test']

Comment on lines -138 to +141
logging.info("Using existing file {}.".format(dst))
logging.info(f"Using existing file {dst}.")
else:
if os.path.isdir(storage_path):
# if only dirname is provided, suffix with basename of URL.
raise ValueError(
"Expecting storage_path to be a file path, got directory {}".format(
storage_path
)
f"Expecting storage_path to be a file path, got directory {storage_path}"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function BaseDatasetBuilder._download_ann 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.

0 participants