如何解决Databricks 上的 STAN - AttributeError: 'ConsoleBuffer' 对象没有属性 'closed'
在 Databricks 8.2 ML 上运行 STAN (pystan) 会引发以下错误
要重现,只需运行 https://pystan.readthedocs.io/en/latest/
中的简单示例似乎 ConsoleBuffer 类没有关闭的实现?有其他人遇到过这个问题吗?有什么解决方法推荐吗?我目前使用的是单节点集群,理想情况下不想在本地机器上运行它。
堆栈跟踪
AttributeError Traceback (most recent call last)
<command-261559943577864> in <module>
3 "sigma": [15,10,16,11,9,18]}
4
----> 5 posterior = stan.build(schools_code,data=schools_data)
6 fit = posterior.sample(num_chains=4,num_samples=1000)
7 eta = fit["eta"] # array with shape (8,4000)
/databricks/python/lib/python3.8/site-packages/stan/model.py in build(program_code,data,random_seed)
468
469 try:
--> 470 return asyncio.run(go())
471 except KeyboardInterrupt:
472 return # type: ignore
/databricks/python/lib/python3.8/asyncio/runners.py in run(main,debug)
41 events.set_event_loop(loop)
42 loop.set_debug(debug)
---> 43 return loop.run_until_complete(main)
44 finally:
45 try:
/databricks/python/lib/python3.8/asyncio/base_events.py in run_until_complete(self,future)
614 raise RuntimeError('Event loop stopped before Future completed.')
615
--> 616 return future.result()
617
618 def stop(self):
/databricks/python/lib/python3.8/site-packages/stan/model.py in go()
438 async def go():
439 io = ConsoleIO()
--> 440 io.error("<info>Building...</info>")
441 async with stan.common.HttpstanClient() as client:
442 # Check to see if model is in cache.
/databricks/python/lib/python3.8/site-packages/clikit/api/io/io.py in error(self,string,flags)
84 The string is formatted before it is written to the output.
85 """
---> 86 self._error_output.write(string,flags=flags)
87
88 def error_line(self,flags=None): # type: (str,Optional[int]) -> None
/databricks/python/lib/python3.8/site-packages/clikit/api/io/output.py in write(self,flags,new_line)
59 formatted += "\n"
60
---> 61 self._stream.write(to_str(formatted))
62
63 def write_line(self,Optional[int]) -> None
/databricks/python/lib/python3.8/site-packages/clikit/io/output_stream/stream_output_stream.py in write(self,string)
19 Writes a string to the stream.
20 """
---> 21 if self.is_closed():
22 raise io.UnsupportedOperation("Cannot write to a closed input.")
23
/databricks/python/lib/python3.8/site-packages/clikit/io/output_stream/stream_output_stream.py in is_closed(self)
114 Returns whether the stream is closed.
115 """
--> 116 return self._stream.closed
AttributeError: 'ConsoleBuffer' object has no attribute 'closed'
解决方法
在尝试了一些旧集群之后,我意识到 pystan 3 是完全重写的。所以一种解决方法是回到 pystan==2.19.1.1
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。