Skip to content

Mac M1 network training issues #2240

Closed
Closed

Description

@jlm2303

Is there an existing issue for this?

  • I have searched the existing issues

Bug description

Hello,

after installation of DLC in miniconda3 environment I am was able to analyze videos with pre-trained networks.

However it is not possible to re-train or train new networks:
The GPU is only used up to 40% while CPU is fully used and after 2.5 hours I reach 1000 iterations.
Afterwards the application memory is depleted and I have to stop the training.

I tried to search for ways to solve this/optimize the GPU usage, but so far I was unsuccessful.
Additionally, also the GUI doesn't show the start of the training, for all other functions you can read what is going in the left corner of the GUI.

Operating System

operating system Ventura 13.3.1

DeepLabCut version

dlc version 2.3.4

DeepLabCut mode

single animal

Device type

32 core GPU
10 core CPU

Steps To Reproduce

  1. install miniconda3 (anaconda3 uninstalled)
  2. Update conda
conda update conda
  1. follow installation steps in DLC installation guide (git clone; cd DLC; conda env create -f DEEPLABCUT_M1.yaml; conda activate DEEPLABCUT_M1)
  2. Update tensorflow packages as first try of trouble shooting
pip uninstall tensorflow-macos
pip uninstall tensorflow-metal
python -m pip install tensorflow-macos==2.9
pip install tensorflow-metal==0.5.0
  1. launch DeepLabCut GUI
  2. Try training network

Relevant log output

/Users/johanna/DeepLabCut/deeplabcut/pose_estimation_tensorflow/core/train.py:227: UserWarning: Switching to Adam, as SGD crashes on Apple Silicon.
  warnings.warn("Switching to Adam, as SGD crashes on Apple Silicon.")
2023-05-12 08:01:18.764393: W tensorflow/core/platform/profile_utils/cpu_utils.cc:128] Failed to get CPU frequency: 0 Hz


Before uninstalling tensorflow packages i got this output:

UserWarning: layer.apply is deprecated and will be removed in a future version. Please use layer.__call__ method instead.
warnings.warn('layer.apply is deprecated and ’
/Users/alan/DeepLabCut/deeplabcut/pose_estimation_tensorflow/core/train.py:227: UserWarning: Switching to Adam, as SGD crashes on Apple Silicon.
warnings.warn(“Switching to Adam, as SGD crashes on Apple Silicon.”)
2023-04-25 01:06:46.456243: W tensorflow/c/c_api.cc:300] Operation ‘{name:‘resnet_v1_50/block2/unit_4/bottleneck_v1/conv1/weights/Assign’ id:913 op device:{requested: ‘’, assigned: ‘’} def:{{{node resnet_v1_50/block2/unit_4/bottleneck_v1/conv1/weights/Assign}} = AssignVariableOp[_has_manual_control_dependencies=true, dtype=DT_FLOAT, validate_shape=false](resnet_v1_50/block2/unit_4/bottleneck_v1/conv1/weights, resnet_v1_50/block2/unit_4/bottleneck_v1/conv1/weights/Initializer/truncated_normal)}}’ was changed by setting attribute after it was run by a session. This mutation will have no effect, and will trigger an error in the future. Either don’t modify nodes after running them or create a new session.
2023-04-25 01:06:46.522643: W tensorflow/c/c_api.cc:300] Operation ‘{name:‘pose/locref_pred/block4/biases/Adam_1/Assign’ id:7170 op device:{requested: ‘’, assigned: ‘’} def:{{{node pose/locref_pred/block4/biases/Adam_1/Assign}} = AssignVariableOp[_has_manual_control_dependencies=true, dtype=DT_FLOAT, validate_shape=false](pose/locref_pred/block4/biases/Adam_1, pose/locref_pred/block4/biases/Adam_1/Initializer/zeros)}}’ was changed by setting attribute after it was run by a session. This mutation will have no effect, and will trigger an error in the future. Either don’t modify nodes after running them or create a new session.

Anything else?

No response

Code of Conduct

Activity

  1. anthonyylee commented on May 12, 2023

    @anthonyylee
    Contributor
    • Would you elaborate what you mean by "the application memory is depleted," and how did you figure this out?
    • What does your CPU memory and utilization look like when the script stops (before training has an opportunity to start)?
      • Reason I asked: When I ran the demo tutorial on a cluster with a GPU, the GPU memory rises to a point (indicating that TF is seeing and using the GPU), however, my Python output will get stuck before training starts (as indicated by the "Starting Training...". And when I ran top on the cluster node, it shows 0 CPU usage on the Python script that is running the training whilst its memory utilization is around 25GB (Unable to start training and low-to-none GPU usage on cluster #2232 ).
  2. jlm2303 commented on May 12, 2023

    @jlm2303
    Author

    On my Mac I had no other programs running and still I got a notification from my mac "Your system has run out of application memory" with python (DCL) taking up more than 90 GB of the memory.

    I checked on the activity monitor and my CPU is oscillating between 98% and 105% and the GPU is used up to 40%.
    I am not sure where I should check the CPU memory itself.

    For me it just shows "failed to get CPU frequency" as indicated above but it can still run the network training.
    I did get to 1000 iterations at a very low learning rate (0.005):

    iteration: 1000 loss: 307168674403079.0000 lr: 0.005
    

    Afterwards either zsh killed python

    zsh: killed     python -m deeplabcut
    

    and for the scenario above as well as when I had to force quit the application, in both cases I got this error message:

    UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown
      warnings.warn('resource_tracker: There appear to be %d '
    

    I hope this can help you with some of your questions!

  3. n-poulsen commented on May 16, 2023

    @n-poulsen
    Contributor

    Hi @jlm2303,

    I was able to reproduce the issues you are having with memory with tensorflow-macos==2.9 and tensorflow-metal==0.5.0. The answer for me was to use the latest version of those packages (tensorflow-macos==2.12.0 and tensorflow-metal==0.8.0), with which I had no issues.

    When it comes to performance (training and inference speed) of TensorFlow on MacOS dropping, this is a known issue that is not related to DeepLabCut. One of our users documented this well and tried different parameters to maximise speed anyways.

    To increase training speed, I would try the following:

    • Increase the batch size (you can do so by editing the training pose_cfg.yaml, which can be done in the "Train network" tab of the GUI). This should increase the GPU usage on your machine. Note that the number of iterations represents the number of batches. So if each iteration takes the same amount of time but your batch size goes from 1 to 16, you are actually training 16 times faster.
    • Train a smaller neural network (such as one of the mobilenets). Documentation about neural net selection is available here.

    Currently, the only way to get very good performance while training is to use an NVIDIA GPU. So if you need better training performance, using Google Colab (there are some demos for that here) or a machine with a dedicated NVIDIA GPU is the way to go.

  4. jlm2303 commented on May 16, 2023

    @jlm2303
    Author

    Hi @n-poulsen,

    many thanks for your help.
    I found the mentioned thread about GPU usage and batch size as well, but since my training never finished I figured it must be something else as well.

    I also started to train my network on a different GPU and for analysis I can use the Mac without problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions