Home Forums Kamanja Forums Data Science & Models Model creation – Static blocks load once

This topic contains 3 replies, has 3 voices, and was last updated by  Archived_User1 1 year, 6 months ago.

  • Author
    Posts
  • #13223 Reply

    Archived_User13
    Participant

    Hi Team,

    Suppose I have a block of code as below

    –static block, execute only once and load serialized data into memory
    {
    …….
    loadTrainedModels
    …….
    }

    — based on loaded data in memory, analyze the input and give result
    String analyzeData(String input){
    …….
    …….
    }

    Please let me know if this can be implemented as a model in Kamanja.

    Thanks,
    Ashwath

  • #13227 Reply

    Archived_User79
    Participant

    A model could read the model specific metadata/information from a container during model creation/execution time. So this requires creating a simple container and populating that with model specific metadata. Kamanja automatically cache this information, so getting it for every message is not any issue with performance, but if model requires to do expensive initialization with this information, then it becomes expensive as this process happens for every message.

    If trained model is small, it could be embedded as part of model code, but I am assuming these models are big and it is not practical to embed as code.

    We are changing model interface so there is notion of initialization (happens once per thread) which allows models to do any expensive initialization operations (such loading and initializing their dynamic data structures) once during its creation and reuse it for each execution. The new interface allows to attach model specific metadata as part of model registration and that would be another mechanism to keep some metadata with each registered model (registered model = model code(PMML/scala/java) + associated metadata).

    There are other workarounds (but not ideal) such as reading from HDFS file during static object initialization (in scala object/in java static class), but that requires hard coding paths. Slightly better way is to read the path from container and use that to load the metadata once during execution time and keep as member in static class. Please ping me offline if you want to go this way as temporary solution.

    The real solution is to fix model interface to allow these kind of initializations.

    Thanks

    -Krishna

  • #13228 Reply

    Archived_User13
    Participant

    Hi Krishna,

    IMHO, changing the model interface to do static initialization would definitely add value and be useful to the user community. Do we have a rough idea on when would this proposed feature be available ?

    Meanwhile I will check with my team on the workaround and will connect offline on the same.

    Thanks,
    Ashwath

  • #13229 Reply

    Archived_User1
    Participant

    Ashwath,
    I posted this as a feature request in our backlog. We are just finishing GA release of 1.1 and we can’t add new features to that. However, we are going to meet today and I will bring this up.
    Donald

Reply To: Model creation – Static blocks load once
Your information: