Skip to content

Commit 0cee897

Browse files
oprypinlearned_optimization authors
authored andcommitted
Replace # pytype: disable suppressions with # pyrefly: ignore
PiperOrigin-RevId: 993589752
1 parent 6a7a031 commit 0cee897

23 files changed

Lines changed: 62 additions & 48 deletions

File tree

‎learned_optimization/baselines/hparam_sets.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def RMSPropMomLR_10000_R5(task_name: str) -> HParamSet: # pylint: disable=inval
121121
reps = 5
122122
cfgs = _lr_cfgs(task_name, "RMSProp", 10000)
123123
for c in cfgs:
124-
c["RMSProp.momentum"] = 0.9 # pytype: disable=unsupported-operands
124+
c["RMSProp.momentum"] = 0.9 # pyrefly: ignore[unsupported-operation]
125125
paths = [(_save_dir_from_cfg(c), reps) for c in cfgs]
126126
return list(cfgs) * reps, paths
127127

@@ -403,7 +403,7 @@ def SM3beta2_999_LR_10000_R5(task_name: str) -> HParamSet: # pylint: disable=in
403403
reps = 5
404404
cfgs = _lr_cfgs(task_name, "SM3", 10000, opt_name_override="SM3beta2_999")
405405
for c in cfgs:
406-
c["SM3.b2"] = 0.999 # pytype: disable=unsupported-operands
406+
c["SM3.b2"] = 0.999 # pyrefly: ignore[unsupported-operation]
407407
paths = [(_save_dir_from_cfg(c), reps) for c in cfgs]
408408
return list(cfgs) * reps, paths
409409

‎learned_optimization/baselines/run_trainer.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ def inner_train_task(
119119
eval_batches=eval_batches,
120120
last_eval_batches=last_eval_batches,
121121
eval_task=eval_task,
122-
device=device) # type: MutableMapping[str, Any] # pytype: disable=annotation-type-mismatch
122+
device=device,
123+
) # type: MutableMapping[str, Any]
123124

124125
results["gin_operative_config"] = gin.operative_config_str()
125126

‎learned_optimization/optimizers/base.py‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def init(self, params, model_state=None, num_steps=None, **kwargs): # pyrefly:
140140
dir_opt_state=self.direction_opt.init(
141141
params, model_state=model_state, num_steps=num_steps, **kwargs))
142142

143-
def update(self, opt_state, grad, model_state=None, **kwargs): # pytype: disable=signature-mismatch # overriding-parameter-count-checks
143+
def update(self, opt_state, grad, model_state=None, **kwargs): # pyrefly: ignore[bad-override]
144144
base_params = opt_state.params
145145

146146
next_mag_opt_state = self.magnitude_opt.update(
@@ -175,28 +175,32 @@ def update(self, opt_state, grad, model_state=None, **kwargs): # pytype: disabl
175175

176176

177177
def SGD(*args, **kwargs): # pylint: disable=invalid-name
178-
from learned_optimization.optimizers import optax_opts # pytype: disable=import-error # pylint: disable=g-import-not-at-top
178+
from learned_optimization.optimizers import optax_opts # pylint: disable=g-import-not-at-top # pyrefly: ignore[missing-module-attribute]
179+
179180
warnings.warn("SGD module has been moved to optax_opts!"
180181
" Calling here from base is deprecated!")
181182
return optax_opts.SGD(*args, **kwargs)
182183

183184

184185
def SGDM(*args, **kwargs): # pylint: disable=invalid-name
185-
from learned_optimization.optimizers import optax_opts # pytype: disable=import-error # pylint: disable=g-import-not-at-top
186+
from learned_optimization.optimizers import optax_opts # pylint: disable=g-import-not-at-top # pyrefly: ignore[missing-module-attribute]
187+
186188
warnings.warn("SGDM module has been moved to optax_opts!"
187189
" Calling here from base is deprecated!")
188190
return optax_opts.SGDM(*args, **kwargs)
189191

190192

191193
def RMSProp(*args, **kwargs): # pylint: disable=invalid-name
192-
from learned_optimization.optimizers import optax_opts # pytype: disable=import-error # pylint: disable=g-import-not-at-top
194+
from learned_optimization.optimizers import optax_opts # pylint: disable=g-import-not-at-top # pyrefly: ignore[missing-module-attribute]
195+
193196
warnings.warn("RMSProp module has been moved to optax_opts!"
194197
" Calling here from base is deprecated!")
195198
return optax_opts.RMSProp(*args, **kwargs)
196199

197200

198201
def Adam(*args, **kwargs): # pylint: disable=invalid-name
199-
from learned_optimization.optimizers import optax_opts # pytype: disable=import-error # pylint: disable=g-import-not-at-top
202+
from learned_optimization.optimizers import optax_opts # pylint: disable=g-import-not-at-top # pyrefly: ignore[missing-module-attribute]
203+
200204
warnings.warn("Adammodule has been moved to optax_opts!"
201205
" Calling here from base is deprecated!")
202206
return optax_opts.Adam(*args, **kwargs)

‎learned_optimization/optimizers/learning_rate_schedules.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __init__(self,
7777
self.constant_fraction = constant_fraction
7878
self.warmup_fraction = warmup_fraction
7979

80-
def __call__(self, global_step, max_steps) -> chex.Array: # pytype: disable=signature-mismatch # overriding-parameter-count-checks
80+
def __call__(self, global_step, max_steps) -> chex.Array:
8181
def fload32(x):
8282
"""Convert input to float32."""
8383
return jnp.asarray(x, dtype=onp.float32)
@@ -191,4 +191,4 @@ def __init__(self, base_lr: float, decay_amount: float):
191191
def __call__(self,
192192
global_step: chex.Array,
193193
max_steps: Optional[chex.Array] = None) -> chex.Array:
194-
return self.base_lr * (1 - self.decay_amount)**global_step # pyrefly: ignore[bad-return]
194+
return self.base_lr * (1 - self.decay_amount) ** global_step

‎learned_optimization/optimizers/optax_opts.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def init(self,
5555
model_state: Optional[ModelState] = None,
5656
num_steps: Optional[int] = None,
5757
key: Optional[chex.PRNGKey] = None):
58-
return OptaxState( # pytype: disable=wrong-arg-types # jax-ndarray
58+
return OptaxState(
5959
params=params,
6060
optax_opt_state=self.opt.init(params), # pyrefly: ignore[bad-argument-type]
6161
state=model_state, # pyrefly: ignore[bad-argument-type]
@@ -188,7 +188,7 @@ def __init__(self,
188188
optax.scale_by_adam(
189189
b1=beta1, b2=beta2, eps=epsilon, eps_root=epsilon_root
190190
),
191-
optax.scale_by_schedule(piecewise_linear(times, vals=lrs)), # pytype: disable=wrong-arg-types # jax-arraylike
191+
optax.scale_by_schedule(piecewise_linear(times, vals=lrs)), # pyrefly: ignore[bad-argument-type]
192192
optax.scale(-1),
193193
)
194194
super().__init__(opt)
@@ -395,7 +395,7 @@ def init(
395395
should_reshape = jax.tree_util.tree_map(lambda x: len(x.shape) == 0, params) # pylint: disable=g-explicit-length-test
396396
params = jax.tree_util.tree_map(_expand_scalar, params, should_reshape)
397397
out = super().init(params, model_state, num_steps, key)
398-
return SM3OptState( # pytype: disable=wrong-arg-types # jax-ndarray
398+
return SM3OptState(
399399
params=out.params,
400400
state=out.state,
401401
optax_opt_state=out.optax_opt_state,

‎learned_optimization/population/examples/complex_cnn/train_threads.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def mutate_fn(
159159
oml_beta2 = onp.log(1 - meta_params["beta2"])
160160
beta2 = 1 - onp.exp(oml_beta2 + onp.random.normal() * 0.03)
161161

162-
return { # pytype: disable=bad-return-type # jax-ndarray
162+
return {
163163
"learning_rate": onp.exp(loglr + offset), # pyrefly: ignore[bad-assignment]
164164
"beta1": beta1, # pyrefly: ignore[bad-assignment]
165165
"beta2": beta2, # pyrefly: ignore[bad-assignment]
@@ -196,7 +196,7 @@ def mutate_fn(
196196
}
197197

198198
initial_population = [initial_meta for _ in range(num_workers)]
199-
initial_population = [mutate_fn(m) for m in initial_population] # pytype: disable=wrong-arg-types # jax-ndarray
199+
initial_population = [mutate_fn(m) for m in initial_population] # pyrefly: ignore[bad-argument-type]
200200
population = population_mod.PopulationController(initial_population, mutator)
201201
server = population_mod.start_courier_server("population", population) # pylint: disable=unused-variable
202202

‎learned_optimization/population/mutators/fixed_schedule.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def update(self, state: Any,
4646
steps = cache[worker.generation_id]
4747

4848
# grab the last checkpoint here.
49-
last_checkpoint = steps.values()[-1] # pytype: disable=unsupported-operands
49+
last_checkpoint = steps.values()[-1] # pyrefly: ignore[bad-index]
5050
logging.info("Active worker: %s", str(worker))
5151
logging.info("last checkpoint : %s", str(last_checkpoint))
5252

‎learned_optimization/population/mutators/single_worker_explore.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def add_worker_to_cache(from_checkpoint: population.Checkpoint,
105105
state["branch_checkpoint"] = steps[0]
106106
state["center"] = steps[0].generation_id
107107

108-
last_checkpoint = steps.values()[-1] # pytype: disable=unsupported-operands
108+
last_checkpoint = steps.values()[-1] # pyrefly: ignore[bad-index]
109109

110110
if state["phase"] == "exploit":
111111
# switch to center.

‎learned_optimization/population/mutators/winner_take_all_genetic.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ def update(
6363

6464
if self._steps_per_exploit:
6565
if (
66-
cache[genid].keys()[-1] - cache[genid].keys()[0] # pytype: disable=unsupported-operands
66+
cache[genid].keys()[-1] - cache[genid].keys()[0] # pyrefly: ignore[bad-index]
6767
) < self._steps_per_exploit:
6868
return None, current_workers
6969

70-
to_test = cache[genid].keys()[0] + self._steps_per_exploit # pytype: disable=unsupported-operands
70+
to_test = cache[genid].keys()[0] + self._steps_per_exploit # pyrefly: ignore[bad-index]
7171
valid_values = [
7272
x.value
7373
for (s, x) in cache[genid].items()

‎learned_optimization/research/brax/brax_env_truncated_step.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def do_step(unroll_state):
152152
action = self.policy.apply(theta, key, unroll_state.env_state.obs)
153153
next_env_state = self.env.step(unroll_state.env_state, action)
154154

155-
out = truncated_step.TruncatedUnrollOut( # pytype: disable=wrong-arg-types # jax-ndarray
155+
out = truncated_step.TruncatedUnrollOut(
156156
loss=-next_env_state.reward, # pyrefly: ignore[bad-argument-type]
157157
is_done=False, # pyrefly: ignore[bad-argument-type]
158158
task_param=None,
@@ -165,7 +165,7 @@ def do_step(unroll_state):
165165
), out
166166

167167
def reset(unroll_state):
168-
out = truncated_step.TruncatedUnrollOut( # pytype: disable=wrong-arg-types # jax-ndarray
168+
out = truncated_step.TruncatedUnrollOut(
169169
loss=0.0, is_done=True, task_param=None, iteration=0, mask=False # pyrefly: ignore[bad-argument-type]
170170
)
171171
unroll_state = BraxEnvState(

0 commit comments

Comments
 (0)