{"record":{"id":"addc175e415f36d9","repo":"apache/beam","slug":"cannot-override-remotemodelhandler-load-model-implement","errorCode":null,"errorMessage":"Cannot override RemoteModelHandler.load_model, implement create_client instead.","messagePattern":"Cannot override RemoteModelHandler\\.load_model, implement create_client instead\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/ml/inference/base.py","lineNumber":461,"sourceCode":"      rate_limiter: A RateLimiter object for setting a global rate limit.\n    \"\"\"\n    # Configure ReactiveThrottler for client-side throttling behavior.\n    self.throttler = ReactiveThrottler(\n        window_ms=window_ms,\n        bucket_ms=bucket_ms,\n        overload_ratio=overload_ratio,\n        namespace=namespace,\n        throttle_delay_secs=throttle_delay_secs)\n    self.logger = logging.getLogger(namespace)\n    self.num_retries = num_retries\n    self.retry_filter = retry_filter\n    self._rate_limiter = rate_limiter\n    self._shared_rate_limiter = None\n    self._shared_handle = shared.Shared()\n\n  def __init_subclass__(cls):\n    if cls.load_model is not RemoteModelHandler.load_model:\n      raise Exception(\n          \"Cannot override RemoteModelHandler.load_model, \",\n          \"implement create_client instead.\")\n    if cls.run_inference is not RemoteModelHandler.run_inference:\n      raise Exception(\n          \"Cannot override RemoteModelHandler.run_inference, \",\n          \"implement request instead.\")\n\n  @abstractmethod\n  def create_client(self) -> ModelT:\n    \"\"\"Creates the client that is used to make the remote inference request\n    in request(). All relevant arguments should be passed to __init__().\n    \"\"\"\n    raise NotImplementedError(type(self))\n\n  def load_model(self) -> ModelT:\n    return self.create_client()\n\n  def retry_on_exception(func):","sourceCodeStart":443,"sourceCodeEnd":479,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/ml/inference/base.py#L443-L479","documentation":"RemoteModelHandler subclasses in Beam's ML inference framework must not override load_model(). The shared client lifecycle (creating one client per worker via shared.Shared) is managed by the base class; subclasses customize only how the client is created (create_client) and how requests are made (request).","triggerScenarios":"Defining a load_model method on a subclass of RemoteModelHandler (e.g. an OpenAI or MTalkGPT handler). At class definition time, __init_subclass__ compares cls.load_model to RemoteModelHandler.load_model and raises immediately — no instance is needed.","commonSituations":"Migrating custom handlers written against the older ModelHandler API (where overriding load_model was the norm) to the remote-handler API; copy-pasting a local ModelHandler implementation and turning it into a remote one; IDE autogeneration of 'abstract' method stubs including load_model.","solutions":["Delete the load_model override from your RemoteModelHandler subclass.","Implement create_client() to construct and return the inference client (move any client construction from load_model there).","Implement request() for the per-request inference call; batching/retry/rate limiting is handled by the base class."],"exampleFix":"# before\nclass MyHandler(RemoteModelHandler):\n  def load_model(self):\n    return openai.Client(api_key=self._api_key)\n\n# after\nclass MyHandler(RemoteModelHandler):\n  def create_client(self):\n    return openai.Client(api_key=self._api_key)\n  def request(self, batch, client, inference_args):\n    ...","handlingStrategy":"validation","validationCode":"assert not 'load_model' in MyHandler.__dict__, 'RemoteModelHandler subclasses must implement create_client, not load_model'","typeGuard":"def valid_remote_handler(cls):\n    return issubclass(cls, RemoteModelHandler) and cls.load_model is RemoteModelHandler.load_model","tryCatchPattern":"try:\n    handler = MyHandler(...)\nexcept Exception as e:\n    if 'Cannot override RemoteModelHandler.load_model' in str(e):\n        raise TypeError('Remove load_model; implement create_client()') from e\n    raise","preventionTips":["Only override create_client and request on RemoteModelHandler subclasses.","Read the RemoteModelHandler docstring before porting a local ModelHandler.","Add a unit test that simply instantiates the subclass — class-definition errors surface immediately."],"tags":["python","apache-beam","ml-inference","class-definition","api-migration"],"backgroundTag":"unsupported-operation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}