Skip to content

CPU never used when MPS is available, if logger is used beforehand #1445

Description

@antonioalegria

System Info

- `Accelerate` version: 0.19.0
- Platform: macOS-13.3.1-arm64-arm-64bit
- Python version: 3.11.3
- Numpy version: 1.24.3
- PyTorch version (GPU?): 2.0.1 (False)
- System RAM: 32.00 GB
- `Accelerate` default config:
	- compute_environment: LOCAL_MACHINE
	- distributed_type: NO
	- mixed_precision: no
	- use_cpu: False
	- num_processes: 1
	- machine_rank: 0
	- num_machines: 1
	- rdzv_backend: static
	- same_network: True
	- main_training_function: main
	- downcast_bf16: no
	- tpu_use_cluster: False
	- tpu_use_sudo: False
	- tpu_env: []
	- dynamo_config: {'dynamo_backend': 'INDUCTOR'}

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • One of the scripts in the examples/ folder of Accelerate or an officially supported no_trainer script in the examples folder of the transformers repo (such as run_no_trainer_glue.py)
  • My own task or dataset (give details below)

Reproduction

Logger used beforehand

Device is set to MPS, although we set cpu to True.

from accelerate import Accelerator
from accelerate.logging import get_logger

logger = get_logger(__name__)
logger.warning(f"Starting test")
accelerator = Accelerator(cpu=True)
print(f"Device: {accelerator.state.device}")

Output:

Starting test
Device: mps

Logger NOT used beforehand

Device is set to CPU, as expected.

from accelerate import Accelerator
from accelerate.logging import get_logger

logger = get_logger(__name__)
# logger.warning(f"Starting test")
accelerator = Accelerator(cpu=True)
print(f"Device: {accelerator.state.device}")

Output:

Device: cpu

Expected behavior

I would expect that whenever cpu=True then device should always be CPU. Also, if I pass a certain device it should use that device. I don't see why using the logger beforehand would have any impact on that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions