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

Add CPU device-id support #150

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions src/insanely_fast_whisper/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
required=False,
default="0",
type=str,
help='Device ID for your GPU. Just pass the device number when using CUDA, or "mps" for Macs with Apple Silicon. (default: "0")',
help='Device ID for your GPU. Just pass the device number when using CUDA, or "mps" for Macs with Apple Silicon or "cpu". (default: "0")',
)
parser.add_argument(
"--transcript-path",
Expand Down Expand Up @@ -91,11 +91,13 @@
def main():
args = parser.parse_args()

dtype = torch.float32 if args.device_id == "cpu" else torch.float16
Copy link
Author

Choose a reason for hiding this comment

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

Added this because otherwise fails on i5 CPU:

RuntimeError: Input type (torch.FloatTensor) and weight type (torch.HalfTensor) should be the same or input should be a MKLDNN tensor and weight is a dense tensor


pipe = pipeline(
"automatic-speech-recognition",
model=args.model_name,
torch_dtype=torch.float16,
device="mps" if args.device_id == "mps" else f"cuda:{args.device_id}",
torch_dtype=dtype,
device=f"cuda:{args.device_id}" if args.device_id.isnumeric() else args.device_id,
model_kwargs={"attn_implementation": "flash_attention_2"} if args.flash else {"attn_implementation": "sdpa"},
)

Expand Down