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

Run notebook end-to-end with GTX 3090/4090 #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

artste
Copy link

@artste artste commented Oct 11, 2023

The main purpose of this PR is to enable users with RTX 3090/4090 cards to run the lm-hackers.ipynb notebook end-to-end. To achieve this, we need to free both the host and GPU memory before loading a new model. The free_memory function below was borrowed from miniai:

def free_memory(verbose=False):
    gc.collect() 
    torch.cuda.empty_cache()
    if verbose: print(f'ℹ️ CUDA MEMORY RESERVED AFTER free_memory: {get_cuda_memory_reserved_gb()} GB')    

Before loading a new model, the current model is deleted, and the free_memory function is called:

del model; free_memory();
mn = "stabilityai/StableBeluga-7B"
model = AutoModelForCausalLM.from_pretrained(mn, device_map=0, torch_dtype=torch.bfloat16)

NOTE: It's essential to use del model before free_memory to ensure that the memory is released before reassignment. Failing to do so might result in a working memory exceeding 24GB.

Added convenience function `free_memory` borrowed from `miniai` to free host and cuda memory_reserved.

NOTE: With this modification it's possible to run the notebook end-to-end using GTX 3090/4090 card.
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant