Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygo-agent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Biluo Shen
ygo-agent
Commits
f6ad8563
Commit
f6ad8563
authored
Jul 16, 2024
by
sbl1996@126.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add expire for duel states in server
parent
7888000e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
5 deletions
+25
-5
ygoinf/setup.py
ygoinf/setup.py
+1
-1
ygoinf/ygoinf/features.py
ygoinf/ygoinf/features.py
+6
-2
ygoinf/ygoinf/server.py
ygoinf/ygoinf/server.py
+18
-2
No files found.
ygoinf/setup.py
View file @
f6ad8563
...
@@ -3,7 +3,7 @@ from setuptools import setup, find_packages
...
@@ -3,7 +3,7 @@ from setuptools import setup, find_packages
__version__
=
"0.0.1"
__version__
=
"0.0.1"
INSTALL_REQUIRES
=
[
INSTALL_REQUIRES
=
[
"numpy"
,
"numpy
==1.26.4
"
,
"optree"
,
"optree"
,
"fastapi"
,
"fastapi"
,
"uvicorn[standard]"
,
"uvicorn[standard]"
,
...
...
ygoinf/ygoinf/features.py
View file @
f6ad8563
from
enum
import
Enum
from
enum
import
Enum
from
itertools
import
combinations
from
itertools
import
combinations
import
time
from
typing
import
List
from
typing
import
List
...
@@ -1061,6 +1062,8 @@ class PredictState:
...
@@ -1061,6 +1062,8 @@ class PredictState:
self
.
reset
()
self
.
reset
()
self
.
_timestamp
=
time
.
time
()
def
reset
(
self
):
def
reset
(
self
):
self
.
_probs
=
None
self
.
_probs
=
None
self
.
_actions
=
None
self
.
_actions
=
None
...
@@ -1080,6 +1083,7 @@ class PredictState:
...
@@ -1080,6 +1083,7 @@ class PredictState:
self
.
_action_msg
=
input
.
action_msg
self
.
_action_msg
=
input
.
action_msg
self
.
_turn
=
input
.
global_
.
turn
self
.
_turn
=
input
.
global_
.
turn
self
.
_phase
=
input
.
global_
.
phase
self
.
_phase
=
input
.
global_
.
phase
self
.
_timestamp
=
time
.
time
()
def
revert_pad_truncate
(
probs
,
n_actions
):
def
revert_pad_truncate
(
probs
,
n_actions
):
if
len
(
probs
)
<
n_actions
:
if
len
(
probs
)
<
n_actions
:
...
...
ygoinf/ygoinf/server.py
View file @
f6ad8563
...
@@ -3,6 +3,7 @@ os.environ.setdefault("JAX_PLATFORMS", "cpu")
...
@@ -3,6 +3,7 @@ os.environ.setdefault("JAX_PLATFORMS", "cpu")
from
typing
import
Union
,
Dict
from
typing
import
Union
,
Dict
import
time
import
time
import
threading
import
uuid
import
uuid
from
contextlib
import
asynccontextmanager
from
contextlib
import
asynccontextmanager
...
@@ -25,13 +26,28 @@ class Settings(BaseSettings):
...
@@ -25,13 +26,28 @@ class Settings(BaseSettings):
code_list
:
str
=
"code_list.txt"
code_list
:
str
=
"code_list.txt"
checkpoint
:
str
=
"latest.flax_model"
checkpoint
:
str
=
"latest.flax_model"
enable_cors
:
bool
=
Field
(
default
=
True
,
description
=
"Enable CORS"
)
enable_cors
:
bool
=
Field
(
default
=
True
,
description
=
"Enable CORS"
)
state_expire
:
int
=
Field
(
default
=
3600
,
description
=
"Duel state expire time in seconds"
)
test_duel_id
:
str
=
Field
(
default
=
"9654823a-23fd-4850-bb-6fec241740b0"
,
description
=
"Test duel id"
)
settings
=
Settings
()
settings
=
Settings
()
all_models
=
{}
all_models
=
{}
duel_states
:
Dict
[
str
,
PredictState
]
=
{}
duel_states
:
Dict
[
str
,
PredictState
]
=
{}
def
delete_outdated_states
():
while
True
:
current_time
=
time
.
time
()
for
k
,
v
in
list
(
duel_states
.
items
()):
if
k
==
settings
.
test_duel_id
:
continue
if
current_time
-
v
.
_timestamp
>
settings
.
state_expire
:
del
duel_states
[
k
]
time
.
sleep
(
600
)
# Start the thread to delete outdated states
thread
=
threading
.
Thread
(
target
=
delete_outdated_states
)
thread
.
daemon
=
True
thread
.
start
()
@
asynccontextmanager
@
asynccontextmanager
async
def
lifespan
(
app
:
FastAPI
):
async
def
lifespan
(
app
:
FastAPI
):
...
@@ -43,7 +59,7 @@ async def lifespan(app: FastAPI):
...
@@ -43,7 +59,7 @@ async def lifespan(app: FastAPI):
print
(
f
"loaded checkpoint from {checkpoint}"
)
print
(
f
"loaded checkpoint from {checkpoint}"
)
state
=
new_state
()
state
=
new_state
()
test_duel_id
=
"9654823a-23fd-4850-bb-6fec241740b0"
test_duel_id
=
settings
.
test_duel_id
duel_states
[
test_duel_id
]
=
state
duel_states
[
test_duel_id
]
=
state
yield
yield
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment