Skip to content
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

Remove Composer imports #928

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions llmfoundry/utils/huggingface_hub_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ def process_file(
node.module.startswith('composer') or
node.module.startswith('omegaconf')):
nodes_to_remove.append(node)
# Remove names starting with 'Composer' from ImportFrom nodes
elif isinstance(node, ast.ImportFrom):
# Filter out names that start with 'Composer'
node.names = [
name for name in node.names
if not name.name.startswith('Composer')
]
# If all names are removed, mark the whole import statement for removal
if not node.names:
nodes_to_remove.append(node)
# Remove the Composer* class
elif (isinstance(node, ast.ClassDef) and
node.name.startswith('Composer')):
Expand All @@ -93,6 +103,19 @@ def process_file(
isinstance(node.targets[0], ast.Name) and
node.targets[0].id == '__all__'):
nodes_to_remove.append(node)
__all__names = []
for elt in node.value.elts:
if not elt.s.startswith('Composer'):
__all__names.append(elt.s)
# Create a new __all__ assignment node if there are any names left
if __all__names:
new_all_node = ast.Assign(
targets=[ast.Name(id='__all__', ctx=ast.Store())],
value=ast.List(
elts=[ast.Str(s=name) for name in __all__names],
ctx=ast.Load()))
ast.fix_missing_locations(new_all_node)
tree.body.insert(0, new_all_node)

transformer = DeleteSpecificNodes(nodes_to_remove)
new_tree = transformer.visit(tree)
Expand Down
Loading