Skip to content

Commit

Permalink
Fixes for issue #1683: failed to run accelerate config in colab
Browse files Browse the repository at this point in the history
refactor the code, passed black, ruff, doc-builder test; modified the prompt in colab.
  • Loading branch information
Erickrus authored Jul 11, 2023
1 parent c94b1b4 commit 7ba6852
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/accelerate/commands/menu/selection_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,18 @@
"""
Main driver for the selection menu, based on https://github.com/bchao1/bullet
"""
import builtins
import pkgutil
import sys

original_input = input
in_colab = False
try:
from google.colab import drive

in_colab = True
except:
pass

from . import cursor, input
from .helpers import Direction, clear_line, forceWrite, linebreak, move_cursor, reset_cursor, writeColor
from .keymap import KEYMAP


in_colab = pkgutil.find_loader("google.colab") is not None


@input.register
class BulletMenu:
"""
Expand Down Expand Up @@ -116,7 +112,10 @@ def run(self, default_choice: int = 0):
if self.prompt:
linebreak()
forceWrite(self.prompt, "\n")
forceWrite("Please select a choice using the arrow or number keys, and selecting with enter", "\n")
if in_colab:
forceWrite("Please input a choice index (starting from 0), and press enter", "\n")
else:
forceWrite("Please select a choice using the arrow or number keys, and selecting with enter", "\n")
self.position = default_choice
for i in range(len(self.choices)):
self.print_choice(i)
Expand All @@ -125,7 +124,7 @@ def run(self, default_choice: int = 0):
with cursor.hide():
while True:
if in_colab:
choice = int(original_input())
choice = int(builtins.input())
else:
choice = self.handle_input()
if choice is not None:
Expand Down

0 comments on commit 7ba6852

Please sign in to comment.