sparseml icon indicating copy to clipboard operation
sparseml copied to clipboard

Move Session Management to Top Level

Open Satrat opened this issue 1 year ago • 1 comments

Previously to create, retrieve, or reset a session we needed to import import sparseml.core.session as session_manager. This file is now a top level import so instead the functions can be called by

  • from sparseml import create_session, reset_session, active_session OR
  • import sparseml -> sparseml.create_session(), etc

Examples

Reset sessions between runs:

import sparseml

oneshot(.....)
sparseml.reset_session()
oneshot(....)

You can also use the create_session context manager to do this cleanup automatically. See tests/sparseml/transformers/finetune/test_finetune.py:test_oneshot_then_finetune() for a full example of this

import sparseml

with sparseml.create_session():
   oneshot(...)

with sparseml.create_session():
   oneshot(...)

Getting info from the current active session:

import sparseml

session = sparseml.active_session()
active_model = session.state.model
session_recipe = session.lifecycle.recipe_container.compiled_recipe 

Satrat avatar May 01 '24 15:05 Satrat

My only suggestion is to change the recommended usage to be explicitly using import sparseml to be clear what the "session" is connected to i.e.

import sparseml

oneshot(.....)
sparseml.reset_session()
oneshot(....)

with sparseml.create_session():
   oneshot(...)

mgoin avatar May 02 '24 16:05 mgoin