Skip to content

feat: Add option to pass QAICInferenceSession to TextGeneration #356

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

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

Conversation

quic-shagun
Copy link
Contributor

Every time cloud_ai_100_exec_kv is called, a QAICInferenceSession gets created and the model is loaded. This makes the entire execution very slow from an application point of view.

This PR gives the user the option to create a session once and send it to the TextGeneration class to be reused for every call.

@quic-amitraj quic-amitraj marked this pull request as draft April 11, 2025 12:19
) -> None:
self._ctx_len = ctx_len
self._write_io_dir = write_io_dir
self.is_tlm = is_tlm

# Load QPC
self._session = QAICInferenceSession(qpc_path, device_id, enable_debug_logs=enable_debug_logs)
self._session = (
session if session else QAICInferenceSession(qpc_path, device_id, enable_debug_logs=enable_debug_logs)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we store this session somewhere while creating it, so we fetch it from the path directly, somewhat like we do for qpc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand, session is an object of QAICInferenceSession. I need to pass it as a parameter. How can I get it from a path?

Copy link
Contributor

@asmigosw asmigosw May 7, 2025

Choose a reason for hiding this comment

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

I mean user would not be able to pass this object, so make we make use of object created this time and not have it as a param. Maybe we can make QAICInferenceSession like a singleton class something like below:

class QAICInferenceSession:
    session = None

    def __new__(cls, *args, **kwargs):
        if not cls.session:
            cls.session= super(QAICInferenceSession, cls).__new__(cls)
        return `cls.session

@@ -322,6 +322,8 @@ def cloud_ai_100_exec_kv(
automation=False,
prompt_to_lora_id_mapping: Optional[List[int]] = None,
is_tlm: bool = False,
session: Optional[QAICInferenceSession] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add this same param in latency_stats_bertstyle function as well so we don't need to create new session there also.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will add

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.

2 participants